You need to attach the
async callback1, that receives the data for your socket, on its behalf and then alerts you that data has been received. You cannot attach a receive function, as it might be blocking. You can argue, that,
SOCK.Receive(buffer, offset, SOCK.Available, SocketFlags.None);
would read the bytes, but no, because even in this case, Available will be 0 as the device might have not yet sent a message, thus it will return,
acting as a non-blocking call. A good approach is to use a callback, and do a BeginReceive(...), and asynchronously read from the wire,
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
Please review this documentation to learn a bit more on the topic,
Asynchronous Client Socket Example | Microsoft Docs[
^], and if you are writin this as a server application, then go through this,
Asynchronous Server Socket Example | Microsoft Docs[
^]
1. I italicized that, because it is funny to consider a callback, and asynchronous approach in 21st century.