1

I use TCP socket to connect a client(source) and a server(destination), the connection has been established. Now the project need to change the source port without interrupt the connection. Both client and server are ubuntu.

For example, suppose that the connection has been establised, the client and server are transmitting data. By using tcpdump on server, we find that the source port from client is 1234. Now we run a tiny port-change tool, then the source port captured on server will be changed to 5678, while the same connection will not be terminated.

Can we reach this goal? If we can, what should I do? If not, why? Thanks for your help!

1
  • 2
    Sadly, host configuration and programing questions are off topic here. But briefly, a connection is defined by, among other things, source and destination ports. If you change one, it is a different connection.
    – Ron Trunk
    Apr 29 at 12:30

1 Answer 1

1

Now the project need to change the source port without interrupt the connection.

Since a connection is identified by the source and destination IP and TCP addresses, changing any one of those four values means it is a different connection, and you will break the original connection.

RFC 793, Transmission Control Protocol explains it:

Multiplexing:

To allow for many processes within a single Host to use TCP communication facilities simultaneously, the TCP provides a set of addresses or ports within each host. Concatenated with the network and host addresses from the internet communication layer, this forms a socket. A pair of sockets uniquely identifies each connection. That is, a socket may be simultaneously used in multiple connections.

The binding of ports to processes is handled independently by each Host. However, it proves useful to attach frequently used processes (e.g., a "logger" or timesharing service) to fixed sockets which are made known to the public. These services can then be accessed through the known addresses. Establishing and learning the port addresses of other processes may involve more dynamic mechanisms.

Connections:

The reliability and flow control mechanisms described above require that TCPs initialize and maintain certain status information for each data stream. The combination of this information, including sockets, sequence numbers, and window sizes, is called a connection. Each connection is uniquely specified by a pair of sockets identifying its two sides.

When two processes wish to communicate, their TCP's must first establish a connection (initialize the status information on each side). When their communication is complete, the connection is terminated or closed to free the resources for other uses.

Since connections must be established between unreliable hosts and over the unreliable internet communication system, a handshake mechanism with clock-based sequence numbers is used to avoid erroneous initialization of connections.

Not the answer you're looking for? Browse other questions tagged or ask your own question.