question

Sakamoto Ko avatar image
0 Likes"
Sakamoto Ko asked Sakamoto Ko commented

How to receive multiple HTTP requests without reconnecting many times.

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

FlexSim 21.0.10
http
5 |100000

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

1 Answer

·
Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Sakamoto Ko commented

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
· 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.

Sakamoto Ko avatar image Sakamoto Ko commented ·

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 0 ·

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.