Local Area Network Audio intercom involves audio collection, audio playback, network transmission, and other technologies. multi-thread processing is required.
First, two types of data are transmitted in the network, namely command data (signaling) and audio data.
Second, any end of the intercom needs to receive audio data, play the audio at the same time, collect the audio, and send the audio data.
Third, you do not need to process packet loss and sort packets in TCP mode.
4. Call the client to initiate an intercom request and call the client to receive the request as a server.
The server opens a listening thread and waits for the client to connect. When the accept in the listening thread returns a valid socket (indicating a successful connection between the client and the server), open a receiving data thread recvthread and processthread for the socket. Recvthread is used to receive audio data and messages sent from the client and store them in the data buffer zone. Processthread reads, analyzes, and processes data from the data buffer zone.
If the sender sends 10 times of data, each time it is 1280 bytes, it does not mean that the receiver will receive 10 times, because each time the receiver receives more than 1280 bytes, and, not necessarily an integer multiple of 1280, that is to say, the received data is not a complete package, and the remaining data will be received at the next time. Therefore, you can set a Data Length in a fixed-length header to read the data length in the header to determine how much data needs to be read.
Source code: http://download.csdn.net/source/3194636