question

Tuan avatar image
0 Likes"
Tuan asked Jeanette F commented

Once I run the first step, subsequent actions will be executed automatically

The file is socket server.

The file communicates with the client through socket.

The first step is to create socket and waiting for the client to connect. (I have to click run)

The second step is to receive the messages from the client after the connection, , and then to run the model for 100 seconds. (I have to click run to receive the message and run the model)

The third step is to send the entire table of numbers (results)to the client.(I have to click run)

Finally, close the socket.(I have to click run)


Once I run the code(The first step), subsequent actions will be executed automatically without clicking run. This is my question.

In other words.

Waiting for the client to connect and automatically receiving the client messages, after running the code(the first step), and automatically running the model for 100 seconds, and automatically sending the results to the client, and finally, closing socket automatically.

擷取.png

GUI_Socket_InterArrivalTime.fsm

FlexSim 20.0.10
communication socketflexsript
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @Tuan, was one of Kavika F's or Tuan's answers helpful? If so, please click the "Accept" button at the bottom of the one that best answers your question. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
Kavika F avatar image
0 Likes"
Kavika F answered Kavika F commented

Hey @Tuan, the reason they won't run all together is because of the "return" statements. When the code executes the first "return", it will end the script. If you want to run all of the code together, you should remove all the return statements and leave the last one. If you need the values returned from those scripts, then you can save them into variables.

Additionally, you could put each of these 4 scripts into "User Commands" and then execute them sequentially in one script without having all of the code visible.

· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Tuan avatar image Tuan commented ·

@Kavika F

If I remove the return and merge the first three scripts,

the code for waiting to receive client's message needs to be added between the first script and the second script

How to write this code?

the code for waiting for the model to run for 100 seconds between the second script and the third script

How to write this code?

0 Likes 0 ·
Kavika F avatar image Kavika F ♦ Tuan commented ·
You can use the Delay class to wait.
0 Likes 0 ·
Tuan avatar image Tuan Kavika F ♦ commented ·

@Kavika F

My version is 2020

If I run a flexscript, I want to run the first half of the code and wait 30 seconds before running the second half of the code

How to write code to delay?

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.