ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 12-15-2008
Nico Zahn's Avatar
Nico Zahn Nico Zahn is offline
Flexsim User
 
Join Date: Sep 2007
Location: Bingen am Rhein, Germany
Posts: 179
Downloads: 19
Uploads: 4
Thanks: 66
Thanked 60 Times in 32 Posts
Rep Power: 201
Nico Zahn has a spectacular aura aboutNico Zahn has a spectacular aura about
Default Testing socket communication

Hi,
I need to check if a connecion established by a clientconnect(); is still active. I tried by setting up a dummy connection to the same host and port and immediatly disconnect the testsocket again. This works fine if the host is still offline. But if the host has gone online again, the connections established before are gone and the testconnection is doing fine...

Is there a way to get an event when the connection is going down?

Is there an event when a message is received by an active connection or do you have to chek in a given intervall?
__________________
kind regards Nico.
  #2  
Old 12-15-2008
AJ Bobo's Avatar
AJ Bobo AJ Bobo is offline
Flexsim Senior Developer
 
Join Date: Jul 2007
Posts: 108
Downloads: 8
Uploads: 0
Thanks: 23
Thanked 89 Times in 41 Posts
Rep Power: 221
AJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the rough
Default

Nico,

There isn't a command that will let you test whether or not a previously-established connection is still active. Your best bet is probably to send a message to the server. If the clientsend() command returns 0 then the message was not sent correctly, and the connection is probably gone. Of course, the server has to be programmed to handle (or correctly ignore) the test message that you send.

Some commands to test the current status of the connections would be nice. I'll put that on the development list.

A.J.
  #3  
Old 12-16-2008
Nico Zahn's Avatar
Nico Zahn Nico Zahn is offline
Flexsim User
 
Join Date: Sep 2007
Location: Bingen am Rhein, Germany
Posts: 179
Downloads: 19
Uploads: 4
Thanks: 66
Thanked 60 Times in 32 Posts
Rep Power: 201
Nico Zahn has a spectacular aura aboutNico Zahn has a spectacular aura about
Default

Hi AJ,
thanks for putting this to the development list.

It would also be great to have an attribute like the other onSomthinghappens for the receiving of a signal on a socket. So you could set up an event and would not need to poll all the time...
__________________
kind regards Nico.
  #4  
Old 12-16-2008
AJ Bobo's Avatar
AJ Bobo AJ Bobo is offline
Flexsim Senior Developer
 
Join Date: Jul 2007
Posts: 108
Downloads: 8
Uploads: 0
Thanks: 23
Thanked 89 Times in 41 Posts
Rep Power: 221
AJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the rough
Default

Nico,

Having triggers like that would be convenient. The problem is that the sockets are not controlled by objects like the rest of the logic in a model. I'm not 100% sure how we'd write easy-to-use triggers for them. But it's a great idea. Maybe we can find a way.

A.J.
  #5  
Old 12-16-2008
Nico Zahn's Avatar
Nico Zahn Nico Zahn is offline
Flexsim User
 
Join Date: Sep 2007
Location: Bingen am Rhein, Germany
Posts: 179
Downloads: 19
Uploads: 4
Thanks: 66
Thanked 60 Times in 32 Posts
Rep Power: 201
Nico Zahn has a spectacular aura aboutNico Zahn has a spectacular aura about
Default

Hi AJ,
what abot the WSAWaitForMultipleEvents Function. It´s documented in the http://msdn.microsoft.com/en-us/library/ms742219(VS.85).aspx

As I (no programmer) understand it waits for an event in the socket communication ?

How did you implement the socket communication in Flexsim? Which librarys are included already when I use C-Code?
__________________
kind regards Nico.
  #6  
Old 12-17-2008
Tom David's Avatar
Tom David Tom David is offline
Flexsim User
 
Join Date: Aug 2007
Location: Schwaebisch Gmuend, Germany
Posts: 430
Downloads: 157
Uploads: 47
Thanks: 486
Thanked 450 Times in 233 Posts
Rep Power: 520
Tom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant future
Default

I had a look into the development list and did not found Nico’s request. Anyway, I went there because I wanted to support his requests regarding sockets. In Germany we have quite some users (as mentioned in another thread) who are using this stuff (like Nico). I like to see improvements here.
__________________
tom the (A)tom: "We have solved our problems ... now we have to fight the solutions."
  #7  
Old 12-17-2008
AJ Bobo's Avatar
AJ Bobo AJ Bobo is offline
Flexsim Senior Developer
 
Join Date: Jul 2007
Posts: 108
Downloads: 8
Uploads: 0
Thanks: 23
Thanked 89 Times in 41 Posts
Rep Power: 221
AJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the rough
Default

Nico,

Event handling in C/C++ is a little different than in Flexsim. I don't have much experience with it, but as I understand it, you often have to pass in a pointer to a function that will be executed when the event occurs. I'm sure we could find a way to do this in Flexsim, but it would not be a trivial amount of work to do. I agree, though, that this would be an excellent feature to add to Flexsim in the future.

Tom,

I put both of Nico's requests on the development list, but it doesn't always like to show the latest version of the file when the web-page loads. Browsers tend to use a cached version of the list, so you don't always see the latest stuff.
  #8  
Old 12-18-2008
Nico Zahn's Avatar
Nico Zahn Nico Zahn is offline
Flexsim User
 
Join Date: Sep 2007
Location: Bingen am Rhein, Germany
Posts: 179
Downloads: 19
Uploads: 4
Thanks: 66
Thanked 60 Times in 32 Posts
Rep Power: 201
Nico Zahn has a spectacular aura aboutNico Zahn has a spectacular aura about
Default

Hi Aj,
I have a question concerning the clientsend(num socket, str message); command.
I connect Flexsim and 'Connecting Sockets' lets say by port 1801.
I use a clientsend every second form Flexsim to Connecting sockets.
If I disconnect 'Connecting Sockets' and I reconnect after lets say 10 s, all messages which where send to 1801 are received at once...
Is Flexsim buffering the messages send to a port that once was connected....
This is an important question for me, because if the messages are not buffered, then I would need to send everything which was send while the connection was down again....otherwise I do not need to take any action because the buffer is keeping the meanwhile send messages...?
__________________
kind regards Nico.
  #9  
Old 12-18-2008
AJ Bobo's Avatar
AJ Bobo AJ Bobo is offline
Flexsim Senior Developer
 
Join Date: Jul 2007
Posts: 108
Downloads: 8
Uploads: 0
Thanks: 23
Thanked 89 Times in 41 Posts
Rep Power: 221
AJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the rough
Default

Nico,

Any buffering that is happening is not done explicitly by Flexsim. Flexsim's socket commands are really little more than wrappers around the socket commands in the Windows Sockets API. I understand that API enough for basic use, but I don't know many specific details about how it works.

For information about WinSock:
http://msdn.microsoft.com/en-us/library/ms740673(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms740149(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms740121(VS.85).aspx
  #10  
Old 12-19-2008
Nico Zahn's Avatar
Nico Zahn Nico Zahn is offline
Flexsim User
 
Join Date: Sep 2007
Location: Bingen am Rhein, Germany
Posts: 179
Downloads: 19
Uploads: 4
Thanks: 66
Thanked 60 Times in 32 Posts
Rep Power: 201
Nico Zahn has a spectacular aura aboutNico Zahn has a spectacular aura about
Default

Hi AJ,
so the send command in the Winsock Reference is sending the data from a buffer wich is pointed to buy the pointer buf*.

int send(
__in SOCKET s,
__in const char *buf,
__in int len,
__in int flags
);

So I guess Flexsim is providing this buffer, and propably writing in this buffer before the send command can return an error.
How big is this buffer in Flexsim ? How manny signs can I send at once (directly or buffered) with the clientsend command?
Is there some more information about the socket communication commands and how they are implemented in Flexsim.
__________________
kind regards Nico.
  #11  
Old 12-22-2008
AJ Bobo's Avatar
AJ Bobo AJ Bobo is offline
Flexsim Senior Developer
 
Join Date: Jul 2007
Posts: 108
Downloads: 8
Uploads: 0
Thanks: 23
Thanked 89 Times in 41 Posts
Rep Power: 221
AJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the rough
Default

Nico,

The buffer that is being sent is the string that you pass into clientsend(). If you do not provide the length of the string in the clientsend() command then Flexsim attempts to figure out how long the string is. This value is then passed as len to send(). The flags paramter of send() is not used.

If the send() command returns an error of any kind, the clientsend() command returns a 0. Otherwise it returns a 1.
The Following User Says Thank You to AJ Bobo For This Useful Post:
Jörg Vogel (12-24-2008)


Thread Thread Starter Forum Replies Last Post
Socket communication Nico Zahn Q&A 12 11-24-2008 10:10 AM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.