Assume I have a reliable UDP library, and want to tunnel arbitrary TCP connections over it. This is my current approach to doing so, but I feel that it may not be very efficient. Any suggestions are very welcome.
Right now, this seems to work for making simple HTML requests from a browser, but since the server isn't directly connected to the client, it is unable to tell when the client terminates a connection. Is there a better way to do this?
EDIT: No, this is not homework. And please don't bother replying if you aren't aware of the advantages of reliable UDP libraries, or for that matter, haven't heard of them before. Thanks.
there are a few ready to use options:
The most efficient way is when the two endpoints directly communicate to each other. If they communicate with different protocols, you need at least one proxy / gateway / traffic converter / whatever. In this case, there is no way around two of these converters, as you now have 3 parts involved: End point client, network traffic, endpoint server. I don't see how you could make it more efficient under the given circumstances.
As for the terminated connections, if you use a tunnel then use it for all traffic, ie communicate all kinds of requests of both client and server to the other side. If a termination can't be communicated to the server, then the problem is sitting on the client side -- the client end point does not communicate its termination to the client tunnel entry. If it would, then you can transfer this termination to the server.
You're going to have to communicate the loss of the client TCP connection to the server side across your UDP tunnel (and the opposite, if the server should happen to close the connection first).
Otherwise, quite apart from the fact that the HTTP server doesn't know the client has disconnected, you will be leaking connections on the side that didn't initiate the connection closure.
One way to do this would be to reserve a special value of your 32 bit connection ID field - say 0x00000000
or 0xffffffff
- as representing a control packet rather than connection data. Following that is another 4-byte field representing a connection ID, and following that is an opcode field. The first opcode you could define is "Connection terminated".
and similar for the server-side of the tunnel.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.