ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Tips and Tricks
Downloads

Tips and Tricks Share helpful modeling ideas

  #1  
Old 10-20-2015
Logan Gold Logan Gold is offline
Administrator
 
Join Date: Nov 2011
Posts: 6
Downloads: 1
Uploads: 0
Thanks: 0
Thanked 15 Times in 5 Posts
Rep Power: 0
Logan Gold will become famous soon enough
Default Socket Examples

Occasionally we get questions about how FlexSim might be used to communicate with other programs. One solution to that question is to utilize Windows sockets with some FlexScript commands that are built into FlexSim.

Here are two example models showing how you might use those FlexScript commands. One model (sockets_client.fsm) is an example on how you might use FlexSim as a client application with sockets and the other model (sockets_server.fsm) is an example on how you might use FlexSim as a server application with sockets.

Both models use Script windows and User Commands to execute the socket commands (socketinit, servercreatemain, clientconnect, clientsend, serverreceive, and so forth), but the commands can be used anywhere FlexScript is used. The User Commands also use parameters to identify the IP address/hostname and port number to set up and make the connection, so make sure they are using the correct values when trying to make a connection.

Both models can be used simultaneously by running two instances of FlexSim together where sockets_server.fsm receives string data from sockets_client.fsm and displays it in the 3D view. However, other socket applications can be used just as well. I've successfully used a program called Hercules SETUP utility from the HW group in testing both models as the application can act like a client or server.

I've tried to include a number of comments in all the Script windows and the four User Commands to help explain how to use all the socket commands. You'll also find an outline in the comments about what Script windows to run in the necessary order to get it all working.

Both models have been saved using FlexSim 7.5.4.

EDIT on Jan 1, 2016:
I made a mistake with the logic in the first upload of sockets_client.fsm where the socketinit() command was not called and this made it so the model would not connect to any server application using sockets. I have fixed that issue and reuploaded the new model. I also added some parameters to the connecttoserver() User Command in sockets_client.fsm and the startSocket() User Command in sockets_server.fsm that makes it easier to change the hostname and port number in the models. Those changes are also in the reuploaded models. Both models were still saved in FlexSim 7.5.4, but they should still work with FlexSim 7.7.
Attached Files
File Type: zip sockets_example.zip (27.7 KB, 691 views)

Last edited by Logan Gold; 01-05-2016 at 12:04 PM.
The Following 6 Users Say Thank You to Logan Gold For This Useful Post:
Vu Duc Nguyen (02-28-2018)


Thread Thread Starter Forum Replies Last Post
Simulation time independent of socket communication Simon Moosbrugger Q&A 1 04-24-2014 08:22 AM
socket example smin Jeon Q&A 0 07-11-2011 10:15 PM
Testing socket communication Nico Zahn Q&A 10 12-22-2008 12:17 PM
Socket communication Nico Zahn Q&A 12 11-24-2008 10:10 AM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.