How to receive multiple HTTP requests without reconnecting many times.

How to receive multiple HTTP requests without reconnecting many times.

sakamoto_koUFFFM
Enthusiast Enthusiast
29 Views
2 Replies
Message 1 of 3

How to receive multiple HTTP requests without reconnecting many times.

sakamoto_koUFFFM
Enthusiast
Enthusiast

[ FlexSim 21.0.10 ]

Hi.


I'm trying to create a model for Http communication between FlexSim.


However, after sending 3 HTTP requests from the client side, only the first request is received and the server side remains frozen.


client.fsm

スクリーンショット-2022-09-27-1737531.png

server.fsm

スクリーンショット-2022-09-27-175123.png

the output console of client.fsm

スクリーンショット-2022-09-27-17375321.png

In order to receive multiple HTTP requests, do I have to disconnect from the client using servercloseconnection() each time I receive one request?


I'd like to know if there is a way to receive several HTTP requests without having to reconnect several times.


server .fsm

client.fsm

0 Likes
Accepted solutions (1)
30 Views
2 Replies
Replies (2)
Message 2 of 3

JordanLJohnson
Autodesk
Autodesk
Accepted solution

In general, HTTP connections are closed after each request, unless the "Connection: keep-alive" header is sent. FlexSim's HTTP connections use WinHTTP under the hood. It may be that with proper headers sent to the server (and received from the server) that WinHTTP would not expect a disconnect after each request. But even with proper headers, it may be that we'd need to enable that feature. I'll add an item to the dev list to investigate this further.

In the meantime, you have some options:

  • You can change the server to close the connection after each request. When I tried this in the models you sent, communication worked perfectly.
  • You can add a query to the url in your request. Then, on the server side, you could parse the query and return data that way. For example, you could change the url to
    data?data1=1&data2=0&data3=1
    or something like that. Everything after the ? is a query. You can parse the query and send all data requested in one big response. Consider sending response data as JSON; FlexSim has good support for reading and writing JSON. See https://docs.flexsim.com/en/22.2/Reference/CodingInFlexSim/FlexScriptAPIReference/Data/JSON.html
.


Jordan Johnson
Principal Software Engineer
>

Message 3 of 3

sakamoto_koUFFFM
Enthusiast
Enthusiast

Thank you very much for your reply.


I had not thought of the way to include the data in the URL.


And it's good to know that it can handle JSON data!


I will try the method you suggested as soon as possible.


Thanks again.


0 Likes