private void OnSendCallback(IAsyncResult result) { SocketClientResult cRes = SocketClientResult.None; try { if (IsConnected) { Socket socket = result.AsyncState as Socket; socket.EndSend(result); cRes = SocketClientResult.Success; } else { cRes = SocketClientResult.NotConnect; } } catch { cRes = SocketClientResult.Exception; } finally { OnSendCompletedEvent?.Invoke(cRes); } }
public void Send(byte[] data) { try { if (IsConnected) { _socket.BeginSend(data, 0, data.Length, SocketFlags.None, OnSendCallback, _socket); } else { OnSendCompletedEvent?.Invoke(SocketClientResult.NotConnect); } } catch { OnSendCompletedEvent?.Invoke(SocketClientResult.Exception); } }
public void Send(string ip, byte[] dataBuffer) { if (!IsRunning) { OnSendCompletedEvent?.Invoke(ip, SocketServerResult.ServerNotRunning); return; } try { if (dataBuffer != null) { this[ip].Socket.BeginSend(dataBuffer, 0, dataBuffer.Length, SocketFlags.None, OnSendCallback, ip); } } catch { OnSendCompletedEvent?.Invoke(ip, SocketServerResult.Exception); } }
private void OnSendCallback(IAsyncResult result) { SocketServerResult sRes = SocketServerResult.None; string ip = string.Empty; try { ip = result.AsyncState as string; this[ip].Socket.EndSend(result); sRes = SocketServerResult.Success; } catch { sRes = SocketServerResult.Exception; } finally { OnSendCompletedEvent?.Invoke(ip, sRes); } }