question

Catarina avatar image
0 Likes"
Catarina asked Catarina edited

Socket communication Flexsim (Windows) and Linux c++ script

I've been trying to establish a socket communication between Flexsim and a Linux c++ script, but i had no sucess. Someone can help me. I put here the photos of each code i'm using.

FlexSim 24.1.0
windowscommunication socketsocketslinux
· 3
5 |100000

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

Jordan Johnson avatar image Jordan Johnson ♦♦ commented ·
What fails, exactly? Does the C++ code accept the connection? Or does FlexSim not receive the response?

Also, be aware that the On Run Stop trigger fires every time you click the stop button. I would probably just make sure the socket is connected on reset, and then leave it open.

0 Likes 0 ·
Catarina avatar image Catarina Jordan Johnson ♦♦ commented ·

c++ doesn't establish the connection, i'm not receiving the "Hello server" message from Flexsim. And neither the "conncetion accepted" from the c++ code.

0 Likes 0 ·
Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @Catarina, was Jordan Johnson's answer helpful? If so, please click the "Accept" button at the bottom of their answer. 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

Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Catarina commented

I can't debug your C++ program. But I made this demo that works on a local computer (127.0.0.1).

EchoServerDemo.fsm

echo_server.py

The python script makes a simple socket echo server. If you have python installed, you can run the file from a command prompt like so:

cd path/to/folder
python -m echo_server.py

If you run that file, the server just sends and receives in a loop. Once the server is running, you can run the model and see that the model is sending and receiving via the socket. For me, this all worked fine, so I don't think it's an issue with FlexSim's socket code.

It looks like you're trying to connect to a different computer. Sometimes firewalls or other network issues can prevent sockets.

Note: I tested this with Python 3.11.


echoserverdemo.fsm (27.0 KiB)
echo-server.py (669 B)
· 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.

Catarina avatar image Catarina commented ·

hi

I was able to establish the connection. So my previous code was correct, but actually there was a firewall preventing the connection like you said.

Thank you

0 Likes 0 ·