예제 #1
0
 protected virtual void OnClosed(SocketEventArgs e)
 {
     if (Closed != null)
     {
         Closed(this, e);
     }
 }
예제 #2
0
 protected virtual void OnOpen(SocketEventArgs e)
 {
     if (Open != null)
     {
         Open(this, e);
     }
 }
예제 #3
0
 protected virtual void OnDisconnected(SocketEventArgs e)
 {
     if (Disconnected != null)
     {
         Disconnected(this, e);
     }
 }
예제 #4
0
        void OnSocketDataReceived(object sender, SocketEventArgs e)
        {
            lock (_receiveLock) {
                try {
                    // Stores data into temporary stream
                    var oldPos = _receiveStream.Position;
                    _receiveStream.Write(e.Buffer, 0, e.Buffer.Length);
                    _receiveStream.Position = oldPos;
                } catch (Exception ex) {
                    Debug.WriteLine(ex.Message);
                    Disconnect();
                }

                while (true) {
                    object packet = null;
                    try {
                        packet = _protocol.Read(_receiveStream);
                        if (packet == null) break;

                        var evnt = PacketReceived;
                        if (evnt != null) evnt(this, new PeerEventArgs(this, packet));
                    } catch (Exception ex) {
                        Debug.WriteLine(packet + ": " + ex.Message);
                        Disconnect();
                    }
                }
            }
        }
예제 #5
0
 void OnSocketConnectionStateChanged(object sender, SocketEventArgs e)
 {
     if (ConnectionStateChanged == null) return;
     var evnt = ConnectionStateChanged;
     evnt(this, new PeerEventArgs(this, e.ConnectionState));
 }
예제 #6
0
 protected virtual void OnClosed(SocketEventArgs e)
 {
     if (Closed != null)
         Closed(this, e);
 }
예제 #7
0
 protected virtual void OnOpen(SocketEventArgs e)
 {
     if (Open != null)
         Open(this, e);
 }
예제 #8
0
 protected virtual void OnDisconnected(SocketEventArgs e)
 {
     if (Disconnected != null)
         Disconnected(this, e);
 }
예제 #9
0
        private void OnClientDisconnect(object sender, SocketEventArgs e)
        {// notif when client disconnected

        }
예제 #10
0
 private void OnClientConnected(object sender, SocketEventArgs e)
 { 
     // notif when client connected 
 }
예제 #11
0
 /// <summary>On connection accepted.</summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void OnSocketClientSocketAccepted(object sender, SocketEventArgs e)
 {
     var evnt = PeerConnected;
     if (evnt != null) evnt(this, new PeerEventArgs(new Peer(e.Socket, _protocol), ConnectionState.Connected));
 }