ATTENTIONThis 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 |
#1
|
||||
|
||||
Socket communication
Hi,
I am testing TCP/IP comunication by sockets in Flexsim. For the tests I use 'Connecting Sockets' which sets up a virtual server on my localhost. I managed to send and receive messages with numbers and strings from serveral servers with the client-commands in Flexsim. Good so far, but for receiving messages from the server I have to use a char-array which is not available in Flexscript, so I need use a C++ node. Here is the code I use to receive from the socket: int i_socket = getlabelnum(current,"Socket_1"); char c_Buffer[50]; //DEFINE i_temp AND SET CLIENT TO RECEIVE FROM CLIENT NUMBER i_Socket int i_temp = clientreceive(i_socket,c_Buffer,49,1); //NULL TERMINATED THE STRING c_Buffer[i_temp] = 0; pt(concat(c_Buffer)); Is there another way to receive messages from a server by TCP/IP? How can I avoid the char?
__________________
kind regards Nico. |
#2
|
||||
|
||||
Nico,
I have no idea if this works or not, but could you write: string c_Buffer; //DEFINE i_temp AND SET CLIENT TO RECEIVE FROM CLIENT NUMBER i_Socket int i_temp = clientreceive(i_socket, apchar(c_Buffer), 49,1); //NULL TERMINATED THE STRING //c_Buffer[i_temp] = 0; pt(c_Buffer); Because apchar is a flexsim function to cast a string into char. Steven |
#3
|
||||
|
||||
nothing received
Hi Steve,
that was a rapid answer, but unfortunatly it does not work. I tried your suggestion with a string and a apchar, but the clientreceive command always returns a 0...
__________________
kind regards Nico. |
#4
|
||||
|
||||
Nico,
Currently, Flexsim socket commands have to be called from C++ for them to work. They are modeled after the socket commands that exist in Windows, which require using parameters to get information out of a function as well as pass it in. Currently Flexscript doesn't allow that, but C++ does. At some point in the future I'm hoping to update the commands so that they can be used in Flexscript. There hasn't been much demand for it up to this point. A.J. |
#5
|
||||
|
||||
Sorry, A.J. but I disagree with your statement that there hasn’t been much demand for this. Unfortunately I can not see the development list (even if I use IE 7) in the moment, but I am pretty sure that I put a demand for this in the development list some time ago, because some German user asked for it. So I know at least 5 users who asked for it. Unfortunately none of them went to the development and support my development point (maybe they have the same problem like me not reaching the list?).
Anyway, I really see the need for it and I know that a project in Germany is coming up, where we need to use it and we really want prevent compiling. Because modeling building speed is so much faster without compiling.
__________________
tom the (A)tom: "We have solved our problems ... now we have to fight the solutions." |
#6
|
||||
|
||||
Has anybody ever tried putting the socket code in a DLL so that you don't have to compile the model? If it works that really sounds like a win-win situation.
__________________
thats not normal. |
#7
|
||||
|
||||
Tom,
I didn't realize that there were that many people that had asked about it. Updating the socket commands isn't in our development plan right now, but try to put it on the development list again. In the meantime, I think Brandon's suggestion about using the commands in a DLL is the best way to go. For what it's worth, let me explain the reason for the incompatibility. When communicating using TCP/IP and sockets, the data that is sent to your computer is stored in a big buffer. When you call clientreceive() or serverreceive() data is pulled from that buffer. The amount of data in that buffer may be much larger than you want (or are able) to handle at once. The Windows socket commands allow you to deal with this by creating your own smaller buffer (in the form of a character array) and passing that in to the receive() command. That buffer is then filled up to a maximum size that you define. If you did not read the full data buffer, you can continue to call receive() until you do. Flexscript does not allow users to pass in strings that are then changed and passed back. I need to create new receive() commands that return the string that is read, instead of using a user-defined string as a buffer. This may have less capability (in some cases) than the Windows commands, but I think it will work for us. A.J. |
#8
|
||||
|
||||
A.J.,
Thanks for your explanation and I am aware that this is not done in five minutes. That’s why I so patient and just put it into the development list (some time ago) and just wait. Maybe I should have told you that this is quite some issue in our eyes, because the German users use sockets quite a lot. @Brandon and using DLL I know that this is possible and that’s the way to do it in the moment if you want to prevent compiling. But is something you need to understand and to know how to use it and not all users include me are familiar with C++ (I am not a programmer). The last time (also some time ago) when I wanted to create a DLL I read the Wiki Article “Creating DLLs that attach to Flexsim” and downloaded the “DLL Maker.zip” and also the *.h files. And it took me quite some time to make it working (maybe I did something wrong), because in my eyes some files were missing, the link to one of the *.h files was broken (but you can still download it, if you change the link manually, etc.). So at the end I got it working, but was frustrated because I was under time pressure for a project. I guess that was also the reason why I forgot the report this to the community. Sorry. Anyway, thank you both for your comments, hints and help. And please do not get me wrong, I am not complaining, I just give you feedback. And I am absolutely convinced that Flexsim is the best and flexible simulation package out there.
__________________
tom the (A)tom: "We have solved our problems ... now we have to fight the solutions." |
#9
|
||||
|
||||
halt on clientreceive
Hi,
when I use the clientreceive function and det the halt parameter to 0 the modell should stopp, till a message is received from the server. So, the modell stops, but when the message is received, the clock is jumping. I use the clientreceive command on the on entry trigger of a processor. The item enters, the processor, everything stops, till a message is send from the server. The moment the messaeg is received, the clock jumps to the next entrytime of a item, to halt the model again? So there is no processtime to be seen in the animation(as I convey the item over thge processor). Can you please give some information how the halt is done?
__________________
kind regards Nico. |
#10
|
||||
|
||||
Tom,
Check my profile, I'm not a programmer. You can ask AJ or Anthony and they'll both attest to having to put up with my lack of programming ability. Thus the beauty of Flexsim, letting dolts like me program like they shouldn't be able to. I've struggled with the DLL as well but I think that once you get the general jist of it you should be able to quickly put in some functions without too much trouble. My problem seems to be remembering the spetial input parameter that the function needs. I was not suggesting that my answer be the final one, merely that it was the only one at the time that was going to solve your problem. Good Luck, Brandon P.S. Personally, I think that your models are evidence to the fact that your skills in Flexsim are as good as anybody's out there, including mine. Everybody has their strong and weak points, but you shouldn't count yourself short. You're pretty dang good at what you do.
__________________
thats not normal. |
The Following User Says Thank You to Brandon Peterson For This Useful Post: | ||
Tom David (11-24-2008) |
#11
|
||||
|
||||
I think you lost the central theme... and people like me, who often only read the last reply consider the issue as solved.... but it is not... by now..
Hi, when I use the clientreceive function and det the halt parameter to 0 the modell should stopp, till a message is received from the server. So, the modell stops, but when the message is received, the clock is jumping. I use the clientreceive command on the on entry trigger of a processor. The item enters, the processor, everything stops, till a message is send from the server. The moment the messaeg is received, the clock jumps to the next entrytime of a item, to halt the model again? So there is no processtime to be seen in the animation(as I convey the item over thge processor). Can you please give some information how the halt is done?
__________________
kind regards Nico. |
#12
|
||||
|
||||
Nico,
What's happening in your case is that Flexsim's simulation engine is still set as running while you are waiting for the socket message to be received. Flexsim remembers the last real time that it executed an event. The next time it tries to execute an event it checks to see how much real time has passed and tries to execute a bunch of events really quickly so that the simulation clock time is where Flexsim thinks it should be. The easiest way to get around this problem is to stop the simulation clock before you call clientreceive() and start it again when you get the message. For example: stop(1); // The 1 makes the stop() command take a little less time clientreceive(...); go(1); I also use this pattern a lot when I use the msg() command. It's known to cause the same problem with timing if you don't close it quickly. A.J. |
The Following User Says Thank You to AJ Bobo For This Useful Post: | ||
Nico Zahn (11-25-2008) |
#13
|
||||
|
||||
Tom,
I have to agree with Brandon on the DLLs. The first time you try to make one, it's tricky. It was tricky for me. But once I got it figured out it's pretty easy. In fact, because so many of Flexsim's commands are available to you, it's pretty much like programming in Flexsim used to be, when C++ was the only option. It just takes a little bit of time to become comfortable with making DLLs. Once you've built a small model or two using a DLL, you'll be just fine using them in the future. A.J. |