I don't believe there is any event-based socket class available in the BCL, but if you're just looking for something a bit higher level than a bare Socket
, perhaps you should look into TcpClient
. It will handle buffering the underlying stream for you, letting you access it through a StreamReader
and the like:
TcpClient client;
// ... construct, connect, etc ...
new StreamReader(client.GetStream());
If you were using a line based protocol, you'd only need to use StreamReader.ReadLine()
, but StreamReader.Read()
should easily suit your purposes as well.