File Transfer via TCP socket Pipe

I have a question regarding creating a pipe of sequential sockets to forward a TCP flow over N-Hops path (S - - - > M1 - - - > M2 - - - > M3 - - - > D ). The goal is for S to send the file over a TCP socket to D. Therefore, All nodes M1, M2 and M3 will operate in two modes, server and client except S and D, which will operate in one mode only.

My question is that: can I create a pipe of sockets to form this path so as M1 receives the first packet from S, it will froward it directly to M2 and so on (i.e., no waiting on any of the M's to receive the entire file, JUST SEND WHAT EVER YOU receive Immediately )? And based on the available Client/Server TCP socket model, what is required to perform this task if doable?
Last edited on
closed account (3TXyhbRD)
Yes. send() and receive() return the number of bytes successfully sent/received. If you receive a part of the package and do a send() of it to the next node, it will do it as fast as it can. Also keep in mind that send() sends a number of maximum specified bytes, if it managed to send 1 byte, the operation is considered to be terminated and it won't attempt to send the rest.
May i ask what is the point of going through intermediate nodes in your context? Does S not know the address of D? Else, IP routing is what routers are for!
bartoli: All the IPs are known to all nodes. If you think there is a better way to implement this like tunneling, please let us know. Remember, S knows D's IP address. If we allowed routing, the performance on direct routing sometimes is not as we require.
Last edited on
LilJoe: I'll post my first attempt on this soon, and we appreciate your suggestions on that as I'm not a C expert. However, the first problem as I see it is how to keep track of the correct portions of the file (i.e., my goal is to minimize the delay on this path as possible).
Last edited on
Ah ok, so you are in a case where you know a best path than what automatic routilg would take.
Couldn't you send your data to a specific tcp port, and configure NAT on each node from this port to the next node's IP on the same port? This way the tunnelling would be transparent, and the network would be 'aware' of the good route to send the response (ACK, etc..) packets efficiently
The limitation on the testbed I'm working on is that it doesn't allow any sort of IP-layer modification, route change and the like (e.g., IPIP, GRE and NAT setting). So, I have no choice unless working beyond that. Hopefully, I made myself clear this time. And this what comes to mind bynow, which 100% I need your support on.
The C question this time is: can I make a TCP server script to work on both modules, client and server? If so, I'll post the server script in order to improve it that way.
closed account (3TXyhbRD)
You can make one application that does everything, however when launching you need to specify what that application does or run everything: server, client and node.

It is best to have one application designed to be a server, and another to be a client. If the server requires other stuff (like your nodes), it's best if the nodes are another application. So in total you should have 3 applications. The server and client can receive and send streams/datagrams.
Topic archived. No new replies allowed.