In this article
See Also
The following example program creates a client that connects to a server. The client is built +
with an asynchronous socket, so execution of the client application is not suspended while
the server returns a response. The application sends a string to the server and then displays
the string returned by the server on the console.
C# Copy
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-client-socket-example 1/5
11/12/2017 Asynchronous Client Socket Example | Microsoft Docs
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
}
try {
// Create the state object.
StateObject state = new StateObject();
state.workSocket = client;
if (bytesRead > 0) {
// There might be more data, so store the data received so far.
state.sb.Append(Encoding.ASCII.GetString(state.buffer,0,bytesRead));
See Also
Asynchronous Server Socket Example
Using a Synchronous Server Socket
Socket Code Examples
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-client-socket-example 4/5
11/12/2017 Asynchronous Client Socket Example | Microsoft Docs
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-client-socket-example 5/5