Two-way communication in socket programming using C

后端 未结 5 1906
失恋的感觉
失恋的感觉 2020-12-17 17:32

I have a small doubt in socket programming. i am able to send my data from client to server and my server processes the data. The o/p of the data processed, I want to send b

5条回答
  •  爱一瞬间的悲伤
    2020-12-17 17:36

    Technically it is right, the socket is duplex and you can send the data to the same socket you read from:

       SOCKET s = socket()
       ... //Connect
       int size = receive(s,...);
       //make response 
       send(s, ...);
    

    But in practice it depends on what are you going to do. It is possible to hang out socket if you have the following situation:

    1. Process 1 sends very big data (<100K) over the socket by one send operation

    2. Process 2 receives data from 1 by portions and sends small packets to 1 (~20b). It is not a

      confirmations, but some external events. The situation goes into hangout, where the sending buffer of the 2 is full and it stops sending confirmations to 1. 2 and 1 are hanging in their send operations making a deadlock. In this case I'd recommend using two sockets. One for read, one for write.

提交回复
热议问题