Protocol for the reconnector:

 

Message Code Parameters Description
Start Session 0x01 client id - 4 bytes Client->Server. Start a new session for the client. If a session is already active, this will kill it. Client's first message id will be 0x0000. Expects a Session Started or Session Rejected.
Reconnect Session 0x02 client id - 4 bytes
last acked message id - 2 bytes
Client->Server. Reconnect to an active session. Expects a Session Started or Session Rejected.
Session Started 0x03 client code - 4 bytes
last acked message id - 2 bytes
Server->Client. Client session started successfully.
Session Rejected 0x04 client code - 4 bytes Server->Client. Tried to reconnect to a bad session or don't have permission to connect. The TCP stream will close.
End Session The session ends when all connections are closed and the client->server TCP stream closes.
New Connnection 0x10 client message id - 2 bytes
connection id - 2 bytes
ip address - 4 bytes (network order)
port - 2 bytes (network order)
Client->Server. Create a new TCP connection. Expects either Connected or Connect failed. The Window is the number of bytes (divided by 256) that the server is permitted to send to the client prior to receiving an ack. The client window is 0 until the Connected message is received.
Must be acked.
Connected 0x11 server message id - 2 bytes
connection id - 2 bytes
window - 2 bytes
Server->Client. Responds with the same message id as the New Connection message and provides the connection id for the opened  connection.
Must be acked.
Connect failed 0x12 server message id - 2 bytes
connection id - 2 bytes
errno - 2 bytes
Server->Client Responds with the same message id as the New Connection message and indicates failure. Must be acked.
Connection EOF 0x13 message id - 2 bytes
connection id - 2 bytes
Either direction. No further traffic will be sent, but traffic may still be received. The other party should do a shutdown(SHUT_WR). Must be acked.
Connection Closed 0x14 message id - 2 bytes
connection id - 2 bytes
Either direction. Indicates that connection id is completely disconnected. Must be acked.
Data Packet 0x1f message id - 2 bytes
connection id - 2 bytes
window - 2 bytes
length - 2 bytes
data - length bytes
Either direction. Send bytes. Must be acked.
Keepalive 0x1f client message id - 2 bytes
connection id - 2 bytes
window - 2 bytes
length - 2 bytes
connection id is any connection currently open
window is that connection's current receive window in bytes*256.
length is exactly 0.
Ack 0x21 message id - 2 bytes
window - 2 bytes
Either direction. Acknowledge receipt of a message. The other end may remove the message from its buffer.Also specify the remaining number of bytes divided by 256 which the remote end is permitted to send for this connection id.

 

 

Corner case problem: nack and wait sent then proxy-proxy connection fails.