'Use tcp for packets to send packets of data

I want to use tcp for packets of data, not streams, but will it work with simultaneous sending? Will i get new independent socket with independent buffer? I mean a situation in which two computers have not yet finished sending the old packet, but someone already wants to send a new one. As i know socket its a pair of pair of ip and port. Can i have two identical sockets?



Solution 1:[1]

It seems that you have a few things conceptually wrong about Sockets and TCP, but it is hard to figure out what you are really thinking from what you wrote. So I will just give you literal answers to your questions, and leave it to figure out what you are misunderstanding.


I want to use tcp for packets of data, not streams,

TCP is stream oriented. If you want to use them to send packets / messages, you need to do that with an application level protocol that uses TCP as its transport.


but will it work with simultaneous sending?

It is unclear what you mean by simultaneous sending. What is doing the sending? Computers? Processes? Threads? In what sense is simultaneous.


Will i get new independent socket with independent buffer?

Each time you connect, you need a new socket. Each Socket has a single buffer for sending and another for receiving.


I mean a situation in which two computers have not yet finished sending the old packet, but someone already wants to send a new one.

It is not clear what you are trying to say here.

Since each TCP connection is represented by a socket, and you (apparently) have two clients (computers) talking to a third one. There will be two separate sockets on the client side, and two more on the werver side. All 4 sockets will have buffers, making a total of 8.

But if you are talking about two clients ("senders") talking to the same server on a single TCP connection, that is not supported by the TCP protocol. To do that kind of thing, the two clients would in fact need to be the same Process, and they would need to coordinate with the process to share the single (client side) Socket. The Server side would also need to be aware.


As i know socket its a pair of pair of ip and port. Can i have two identical sockets?

You can have multiple sockets connecting different client / server pairs. Or even the same pair.

However, they will not be identical. Each live socket must be distinguishable based on the IP and port numbers. Otherwise, the TCP implementation would not be able to send the data received from the network to the right socket.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stephen C