I am writing a peer-to-peer application where the connection between the two client peers must be duplex, so that both clients are capable of transmitting and receiving at the same time. Is it possible with a single socket or do I need to use two sockets?
WebSocket is a standard protocol that enables a web browser or client application, and a web server application to use a full-duplex connection to communicate.
A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to. An endpoint is a combination of an IP address and a port number.
The CAN network is based on a half-duplex differential signal. There are two logical states: dominant and recessive.
A half-duplex transmission could be considered a one-way street between sender and receiver. Full-duplex, on the other hand, enables two-way traffic at the same time. A communications channel can be used to communicate one way at a time or in both directions at once.
It's possible; sockets on every OS I know of are full duplex - you can transmit and receive at the same time. However to achieve truly full duplex communication, you must ensure that your application can transmit while waiting to receive - this means either using non-blocking IO and event polling (On Linux there's select
and epoll
, or on windows things like WSAAsyncSelect
or overlapping IO) or by using different threads for transmitting and receiving.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With