I see that some applications using TCP can be configured to bind to multiple ports. Does this mean that they open multiple TCP sockets, or it is possible to open a single socket and bind it to many local ports?
Thanks.
A TCP socket can only be bound to a single port. In particular, if you try to bind an already-bound TCP socket to a second port, bind() will return -1 and set errno to EINVAL.
Servers that accept incoming TCP connections on multiple ports are doing it by creating multiple TCP sockets.
I developed a TCP backend using boost asio and now I need to access the whole TCP packet (header + body). It is possible using TCP sockets?
I have a application that has a TCP socket listener that I need to broadcast from a server-side application to. I do not control this TCP listener and can't make any changes to it. Is there any way to broadcast to that listener with WebSockets instead of TCP? I know that WebSockets are an Application Level networking tool that implements a HTTP handshake, among other things, over a TCP connection. Is there any way to strip that extra stuff off?
I ask because the application will be running on Heroku, which does not support TCP connections.
I have tried writing a little talker and listener application and the listener receives a HTTP header and seemingly nothing else when I try to broadcast to it, which is expected.
is there a way to have tcp act more like udp? Im currently using lua sockets and have set the tcp no_delay option, is there a way to disable or set the acknowledgement to timeout?
First of all, is there any problem with using both UDP and TCP on the same server?
Secondly, can I use the same port number?
Yes, you can use the same port number for both TCP and UDP. Many protocols already do this, for example DNS works on udp/53 and tcp/53.
Technically the port pools for each protocol are completely independent, but for higher level protocols that can use either TCP or UDP it's convention that they default to the same port number.
When writing your server, bear in mind that the sequence of events for a TCP socket is much harder than for a UDP socket, since as well as the normal socket and bind calls you also have to listen and accept.
Furthermore that accept call will return a new socket and it's that socket that you'll then have to also poll for receive events. Your server should be prepared to continue accepting connections on the original socket whilst simultaneously servicing multiple clients each of which will be triggering receive events on their own sockets.
Firstly,there is no problem using both tcp and udp on the server.
Secondly,we can have both UDP and TCP requests on same port ,because each request is identified by a quintuple contained by source IP ,Destination IP, Source Port, Destination Port, PROTOCOL(as protocol can be TCP or UDP).