Raw protocal connection to a ME serial port

We use a a software that uses a Raw TCP/IP access to a serial port via port 4000 on the module. The software keeps a constant conection to the digi whilst it is running, and then closes at session end.

The problem there are times when I can look at the connections through the digi web interface and see that the raw connection to the serial port is still open even if the software has been completely shut down. If this is the case the software is unable to reconnect when it is restarted with out a reboot to the module/terminating the connect.

What I am trying to figure out is if there is a time out option on the module that will allow me to say if this connection is idle for more than x number of seconds terminate it.

Does anyone know if this setting is available on the ME module

Thanks in advnace for any help


A simple select() loop will solve that for you. Put a timeout on the select(), then do the recv(). If the recv() returns a 0 or -1, then the port is closed.

Here is a basic select loop template. Run something like this on its own thread and then have something to do your shutdown if it ever breaks the loop.

for( ; ; )
// Wait 10 ms for data
fd_set read_set;
struct timeval wait;

wait.tv_sec = 0;
wait.tv_usec = 10*1000;

 // Look either for Capture or Listen sockets
if( m_sockCapture != INVALID_SOCKET )
	FD_SET(m_sockCapture, &read_set);

FD_SET(m_sockListen, &read_set);

int res = select(FD_SETSIZE, &read_set, NULL, NULL, &wait);
 // Got some data
if( res > 0 )
	 // Listen socket activated
	if( FD_ISSET(m_sockListen, &read_set) )
		 // Close old capture socket
		//FD_CLR(pPM->m_sockCapture, &read_set);
		if( m_sockCapture != INVALID_SOCKET && m_sockCapture )
		 // Accept the new Capture socket
		struct sockaddr from;
		int nFrom = sizeof(from);
		m_sockCapture = accept(m_sockListen, &from, &nFrom);
		if( m_sockCapture == INVALID_SOCKET || m_sockCapture < 0 )
			m_sockCapture = INVALID_SOCKET;
			return true;
	 // Capture socket activated
	else if( FD_ISSET(m_sockCapture, &read_set) )
		 // Get the data
		int nSize = recv(m_sockCapture, (char *)&m_Buffer[m_nBuffer], sizeof(m_Buffer)-m_nBuffer, 0);
		if( nSize > 0 )
			nSize += m_nBuffer;
										 // Process the data
			m_nBuffer = ProcessData(m_Buffer, nSize);
		else if( nSize <= 0 )
			 // Remote Disconnect
			return true;
else if( res < 0 )
	 // Select error
	return true;
else if( res == 0 )
	 // select timeout


Is the timeout for select in milliseconds or microseconds?

I had asked digi tech support and they had told me milliseconds.

In linux it is microseconds.

In your code I think you are assuming microseconds.

It is microseconds for the standard API. Internally it is converted into milliseconds, but that is invisible to you.

Tech Support was wrong. Common misconception.