57
3.accept data
There are many ways for sockets to receive data, and you need to choose according to
the actual scenario application. Here is one of them.
For more usage methods, please refer to the official tutorial
create a new thread
Thread TRec = new Thread(RecvMsg) { IsBackground = true };
TRec.Start();
A loop is opened in the thread to continuously detect whether there is data that needs to
be read
if(_mySocket.Available<=0)
{
Continue;
}
If there is, read the data and process it
byte[] buffer = new byte[_mySocket.Available];
int length = _mySocket.Receive(buffer);
Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, length));
The device supports setting to read the uploaded data that fails to be used for the program
to determine whether the decoding is successful or not, see 6.10