private FinishOperationSyncFailure ( SocketError socketError, int bytesTransferred, SocketFlags flags ) : void | ||
socketError | SocketError | |
bytesTransferred | int | |
flags | SocketFlags | |
return | void |
SocketAsyncEventArgs socketArgs = new SocketAsyncEventArgs(); socketArgs.Completed += OnOperationCompleted; socketArgs.FinishOperationSyncFailure += OnSyncFailure; public void OnSyncFailure(object sender, SocketAsyncEventArgs e) { // Handle synchronous operation failure here }
using System; using System.Net; using System.Net.Sockets; public class SocketListener { private Socket _listener; public void StartListening() { _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _listener.Bind(new IPEndPoint(IPAddress.Any, 1234)); _listener.Listen(100); SocketAsyncEventArgs acceptArgs = new SocketAsyncEventArgs(); acceptArgs.Completed += OnAcceptCompleted; acceptArgs.FinishOperationSyncFailure += OnSyncFailure; _listener.AcceptAsync(acceptArgs); } private void OnSyncFailure(object sender, SocketAsyncEventArgs e) { // Handle synchronous operation failure here } private void OnAcceptCompleted(object sender, SocketAsyncEventArgs e) { if (e.SocketError == SocketError.Success) { Socket connection = e.AcceptSocket; // Handle accepted connection } e.AcceptSocket = null; _listener.AcceptAsync(e); } }Package library: System.Net.Sockets.
private FinishOperationSyncFailure ( SocketError socketError, int bytesTransferred, SocketFlags flags ) : void | ||
socketError | SocketError | |
bytesTransferred | int | |
flags | SocketFlags | |
return | void |