Friday, June 20, 2014

Homemade Internet Service Relay (IV)

Once I started with the implementation, difficulty arise when we have more than one connection. There is just one TCP connection between the internal networks and there are more than one connections between the external world and the internal service. Clearly there is a need to multiplex more than one connections into a single connection. The situation is very much like multiple TCP connections are multiplexed a single piece of network cable.

When multiple TCP connections use the same network cable, the input is broken down into multiple packets. At any time, only one packet got written to the cable. On the receiving end, the network pick up the packet, look at the header, and dispatch the packet to the right connection by port number.

In our case, we will design our multiplexing the same way. First, we define streams. Streams are simply a user-level connection, being multiplexed on top of the underlying TCP connections. Each stream break down its input into frames (similar to an IP packet), and then they are sent through the connection. On the receiving end, the packets are received and re-assemble into a data stream.

Streams are created when a new stream ID is sent. On the receiving a new stream ID a new stream object is created if there are pending accepts. The programming model is the same as normal TCP programming.

No comments :

Post a Comment