Fairly new to the Digi Connect ME device and I am familiarising myself with the device and OS API’s before developing the application we need using NET+OS.
Its all looking fairly good with the Socket handling and sending/receiving data via mapped ports. The main problem I am coming across and cannot find a way of detecting is if the client decides to terminate/disconnect then I have no idea that the port is no longer connected. This has an effect of me not being able to kill the thread or go back to a listen state.
I thought it was the fact that the FIN command wasn’t being received by the Digi but looking with ethereal I see that when I send the disconnect FIN, ACK the Digi returns with an ACK so it has acknowledged that the command has been received.
There must be some way to do it but I have been trawling through the documentation and found nothing.
Any help is greatly appreciated and I’m sure the responses will help others.
Thanks in advance
OK I’ve manage to do something but it seems very crude to me…
I have a thread that initially sets up a socket and places it into listen mode:
so.Create(SOCK_STREAM, htons( (unsigned short) port );
//then setup the Tx and Rx buffer sizes
as listen returns with a success I then create a new non blocking socket :
//Accept connection and store port and IP address for future use
so.Accept(New_so, peer_port, peer_addr);
//Set socket to non blocking
New_so.SetSockOpt(SO_NONBLOCK, &StateSet, sizeof StateSet, SOL_SOCKET);
then enter a loop to receive data and at the moment echo back to the same port:
if ((cnt = New_so.Receive(buffer, 1500, 0)) < 0)
int errorNum = getErrno();
switch( errorNum )
//various error traps.
if (cnt > 0)
New_so.Send(buffer, cnt, 0);
The two things that confuse me is that when I am looping through the RX/TX if there is no data ready the return is -1 as there is an error and GetLastError() returns EWOULDBLOCK which is fair enough.
If I use ReceiveFrom and specify IP and port I get the error EPROTOTYPE yet when using the standarf Receive its acceptable… something not quite right here I think.
The way I can identify that the port has been closed is that the received count is 0 rather than being negative (-1 for nothing) or posotive for some data.
Am I missing something with the ReceiveFrom ??