question

Nil Ns avatar image
0 Likes"
Nil Ns asked Logan Gold answered

ClientConnect Error

Hello,

I am trying to connect to a server using TCP through a VPN.


I am using the following code (not with XX.X.X.X, of course):

// We create a new node to keep track of which connection to use later on. Something else, like
// a Global Variable, could be used for the same purpose.
treenode connection = Model.find("/Tools/connection");
if(!connection){
connection = model().find("Tools").subnodes[1].copy();
connection.name = "connection";
connection.value = 1;
while(connection.subnodes.length > 0){
connection.subnodes[1].destroy();
}
}

string hostname = "XX.X.X.X";
int portnum = 25025;
int client = 0;
// Initialize the socket before trying to create a connection. socketinit() return TRUE
// if the initialization is successful and reutrns FALSE if it is not successful.
if(socketinit()) 
{
client = clientcreate(); // Start the process to use Windows sockets as a client.
}
// clientcreate() returns TRUE if the process could start properly and FALSE if it couldn't.
if( client )
{
// Make the connection to this machine using given hostname and port number.
if(clientconnect(client,hostname,portnum)){
// Set the client node created earlier with the connectin value.
connection.value = client;
/* CODE*/

}
else{
msg("Client Error", "Failed to connect to server."); // The connection could not be made.
if(!clientclose(client))
msg("Socket Error", "Failed to close client socket."); // The socket did not close properly.
return 0; // Return a 0 to indicate an issue.
}
}
else{
int user = msg("Socket Error", "Failed to create client socket."); // The process for socket connection could not start.
if(user != 1){
stop();
}
return client; // Return value in client variable (0) to indicate an error.
}


The clientconnect function always returns False.

I have been testing the connection with a Python file and it works perfectly. Therefore, it seems that the problem is related to Flexsim.


Is it possible that Flexsim does not connect to the VPN? Could it be that the VPN rejects the connection with Flexsim?

I appreciate any help or suggestions you can provide.

FlexSim 23.1.4
tcp
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

Logan Gold avatar image
0 Likes"
Logan Gold answered

I'm guessing this is a network connection issue. I would like to try and replicate the issue with a VPN, but I haven't been able to do so yet.

Here is a Stack Overflow post about an issue that is similar to yours, with a few suggestions that might be helpful for you. I believe they are referring to a C++ command that is the same, or similar, to the one used in FlexSim's clientconnect() command:

https://stackoverflow.com/questions/8004576/connect-failed-through-vpn

As a workaround, since you can get it working with Python, you could always use Python with FlexSim to make the connection instead.

5 |100000

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