clientreceive() read a integer

clientreceive() read a integer

yue_y
Not applicable
544 Views
7 Replies
Message 1 of 8

clientreceive() read a integer

yue_y
Not applicable

[ FlexSim 19.1.1 ]

I want to use clientreceive() to read one integer sent from the server. Is it possible to read four bytes from the socket and convert it to an integer in FlexScript?

0 Likes
Accepted solutions (1)
545 Views
7 Replies
Replies (7)
Message 2 of 8

mischa_spelt
Advisor
Advisor
Accepted solution

Unfortunately clientreceive() only returns strings and FlexSim's string type is not so UTF-8 compliant that you can use that to transmit any integer.

I have written a module a while back that can transmit and receive binary data but it was for 17.0, I think, so it needs an upgrade here and there. Let me know by email if you are interested.

Message 3 of 8

Jacob_Gillespie
Autodesk
Autodesk

@Yue Y As Mischa said the FlexScript command cannot do this. If you use the c++ version of the command from a module then you could convert the bytes into an integer.

0 Likes
Message 4 of 8

yue_y
Not applicable

thank you! How can I use c++ version in the Script? Do I just click the "C" button? In this mode, how can I convert the bytes into an integer, is there any function I can use?

0 Likes
Message 5 of 8

yue_y
Not applicable

I want to read a long message using clientreceive but I don't know the length of the message ahead of time. So that the server would send an integer first, indicating the length of the message. Then FlexSim should read the integer first and then read these amount of characters from the socket. Is it possible? Thank you!

0 Likes
Message 6 of 8

yue_y
Not applicable

Also, for the FlexScript version of clientreceive, if the server sends a bytes while the buffer size is b bytes and a <= b, will FlexScript guarantee to read in all a bytes?

0 Likes
Message 7 of 8

Jacob_Gillespie
Autodesk
Autodesk

To use the c++ version I recommend using the module SKD. Otherwise if you put c++ into the model then you will have to compile it every time.

0 Likes
Message 8 of 8

Jacob_Gillespie
Autodesk
Autodesk

You could send the integer as a string padded to a certain length. Then remove the padding and parse the string as an integer in FlexScript. That way you wouldn't have to use c++.

0 Likes