public virtual void AsyncSend(NetworkData a_oData) { try { NetworkAction?.NetworkStateChanged(NetworkState.Sending, new StateObject(this, a_oData)); NetworkSocket?.BeginSend(a_oData.Buffer, 0, a_oData.DataLength(true), SocketFlags.None, new AsyncCallback(SendCallback), this); } catch (Exception) { NetworkAction?.NetworkStateChanged(NetworkState.Error, new StateObject(this)); } }
protected virtual void AcceptConnection() { try { NetworkAction?.NetworkStateChanged(NetworkState.Listening, new StateObject(this)); m_oNetObject?.BeginAcceptTcpClient(new AsyncCallback(AcceptCallback), this); } catch (Exception e) { NetworkAction?.NetworkStateChanged(NetworkState.Error, new StateObject(this, e)); } }
public virtual void AsyncReceive() { Data?.Clear(); try { NetworkAction?.NetworkStateChanged(NetworkState.Receiving, new StateObject(this)); NetworkSocket?.BeginReceive(Data.Buffer, 0, Data.BufferLength, SocketFlags.None, new AsyncCallback(ReceiveCallback), this); } catch (Exception) { NetworkAction?.NetworkStateChanged(NetworkState.Error, new StateObject(this)); } }
public virtual StateObject SyncReceive() { try { Data?.Clear(); NetworkSocket?.Receive(Data.Buffer, SocketFlags.None); return(new StateObject(this, Data)); } catch (Exception) { } NetworkAction?.NetworkStateChanged(NetworkState.Error); return(null); }
public override void Establish() { if (IsConnected) { return; } try { m_oNetObject.BeginConnect(Address, Port, new AsyncCallback(ConnectCallback), this); NetworkAction?.NetworkStateChanged(NetworkState.Connecting, new StateObject(this)); return; } catch (Exception) { } NetworkAction?.NetworkStateChanged(NetworkState.Error, new StateObject(this)); }
public override void Establish() { if (IsConnected) { return; } try { m_oNetObject.Start(); AcceptConnection(); return; } catch (Exception) { } NetworkAction?.NetworkStateChanged(NetworkState.Error, new StateObject(this)); }