question

yexioamu avatar image
0 Likes"
yexioamu asked Natalie White commented

Can i get the client ip and port which connect to server socket in flexsim

Can i get the remote client ip and port which connect to server socket in flexsim

FlexSim 21.2.4
socket
· 7
5 |100000

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

Natalie White avatar image Natalie White commented ·

You create a server socket that listens for connections to a specified port using servercreatemain(). So, you choose the port number. Your client needs to know the IP address of your server, but I'm not sure if you can access your client's IP address.

Does this help, or were you trying to ask about something else? Would an example of using a socket be useful?

1 Like 1 ·
yexioamu avatar image yexioamu Natalie White commented ·
I mean that I create a server socket in flexsim, I have several clients with different ip and port, when they connect to the server socket, I want to know which client connect, and the client won’t send its own ip and port in the message
0 Likes 0 ·
Natalie White avatar image Natalie White yexioamu commented ·
Got it. Are you trying to send the message with clientsend()? This function can only send a string.

If you're able to attach your model, that would be helpful.

0 Likes 0 ·
Show more comments
Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·

Hi @yexioamu, was one of Natalie White's or Phil BoBo'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 comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
Phil BoBo avatar image
0 Likes"
Phil BoBo answered

The FlexScript socket commands do not give you access to the connecting client's ip address. The serveraccept() function returns an index for the client connection that is subsequently used to receive messages from that client using serverreceive().

If you want more control over the communication than you get with the FlexScript commands, use external code, such as Python or C++. See Connecting to External Code.

See also accept function (C++) or socket.accept (Python).

5 |100000

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

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.