Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a single socket be used for full duplex communication in C? [closed]

Tags:

c

sockets

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?

like image 927
Sreeja Das Avatar asked Nov 04 '12 10:11

Sreeja Das


People also ask

Do Websockets allow full-duplex communication?

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.

Is a socket two-way communication?

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.

CAN protocol is half-duplex or full-duplex?

The CAN network is based on a half-duplex differential signal. There are two logical states: dominant and recessive.

What is the difference between half-duplex and full-duplex communication?

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.


1 Answers

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.

like image 68
bdonlan Avatar answered Sep 20 '22 03:09

bdonlan