Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Closing a TCP Pakbus connection


AHann Jul 3, 2017 01:00 PM

Hi,

I'm running a connection from a CR1000 through a Serial Modem to a remote Loggernet server by first establishing a TCP connection, logging in, then switching to pakbus communications by negating the TCP socket (TCP Callback).

My question is, how do I go about closing the TCP connection following the transfer to pakbus? A snippet of the code I'm using to connect is as follows:

Socket = TCPOpen(Host,Port,1000,1000) ' Open connection to Host
SerialOut(LoginDetails) ' Indicate our presence and login
PakSuccess = TCPClose(0-Socket) ' Change over to Pakbus communications

This works perfectly and data is transferred as anticipated. Having already used TCPClose to switch into PakBus communications how do I now close the connection?

Using:

PakSuccess = TCPClose(Socket)

Returns 0, which I assume means the disconnect was successful.

However, when the connection is re-established the socket increments by one.

On first run Socket = 101

Second, Socket = 102

Which continues I assume until the socket buffer is filled. This seems to indicate that the connection was not closed on the first try and has been re-established?

Is it not necessary to close the TCP connection at all?

Before and after this sequence a PPP connection is opened and closed using PPPOpen and PPPClose, so I assume the same steps are required for a TCP connection?


AHann Jul 4, 2017 03:56 AM

Edit: This doesn't work either. Socket still increments at the beginning of each session. Even when socket isn't explicitly closed in the code. Does anybody know the correct way of closing a TCP Pakbus connection? Just leaving it to increment indefinitely doesn't seem sustainable

---------------------------------------

Just not doing a TCPClose() seems to keep the socket at 101 without incrementing, and everything appears to run as per normal.

Should we not be notifying the server of a disconnect before closing the session by disconnecting the modem from the interwebs (PPPClose)?

Thanks,

Ash

Log in or register to post/reply in the forum.