question

Sakamoto Ko avatar image
1 Like"
Sakamoto Ko asked Sakamoto Ko commented

How to get the proper connection index after executing serveraccept(1).

Hi.


I'm researching Http communication between FlexSim.


I'd like the client to make the connection request after the server side is started.


If I use serveraccept(0), I can do that, but FlexSim will stop.


So I tried to execute serveraccept(1) in server.fsm before client.fsm send the connection request.


As a result, the connection was successful, but the server could not receive data from the client.


I tried to execute serverreceive() assuming the connection index was 1, but that seems to be a mistake.


If I execute serveraccept(1) before the client sends the request, how can I get the proper connection index?


server .fsm

client.fsm

FlexSim 21.0.10
httpcommunication socket
server.fsm (24.3 KiB)
client.fsm (25.2 KiB)
· 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 ·

My apologies, there was a mistake in the two models uploaded previously.

I will upload them here again.


server1.fsm

client1.fsm

0 Likes 0 ·
client1.fsm (24.6 KiB)
server1.fsm (24.3 KiB)

1 Answer

·
Jordan Johnson avatar image
2 Likes"
Jordan Johnson answered Sakamoto Ko commented

The serveraccept() command works in one of two ways, depending on the argument you pass in:

  • serveraccept(0) locks flexsim, waiting for an incoming connection. The return value is the
  • serveraccept(1) checks if, in that instant, something is attempting to connect. If nothing is trying to connect in that instant, then serveraccept(1) returns 0, and stops listening for something to connect, so you cannot get a good value later.

The HTTP API is newer, and so has a way to set callbacks, allowing asynchronous requests. The server*() commands are older, and so can only be used synchronously.

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

Sakamoto Ko avatar image Sakamoto Ko commented ·

Hi @Jordan Johnson .

I understand that serveraccept(1) does not give the correct Connection index later.

Thnak you!

0 Likes 0 ·
Sakamoto Ko avatar image Sakamoto Ko commented ·

I have an additional question.


Since Update 1 of FlexSim2022, a header method has been added to the HTTP API. Can I also change headers such as Connection here?


I was wondering because the official documentation only mentions changing the Conntent-Type.

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦ Sakamoto Ko commented ·

We don't limit what headers you send. It's up to the server to properly handle those headers and take the correct actions, such as keeping the connection alive.

0 Likes 0 ·
Sakamoto Ko avatar image Sakamoto Ko Jordan Johnson ♦ commented ·

I understand that the header can be customized that we wish.

Thank you for answering my many questions!

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.