示例#1
0
 private void ProtocolClient_ConnectionError(ProtocolClient sender, Exception exception)
 {
     lock (syncLock) {
         connectedClients.Remove(sender);
         ConnectionError?.Invoke(sender, exception);
     }
 }
示例#2
0
 private void ProtocolClient_ConnectionEstablished(ProtocolClient sender)
 {
     lock (syncLock) {
         connectedClients.Add(sender);
         ConnectionEstablished?.Invoke(sender);
     }
 }
示例#3
0
        private void AcceptCallBack(IAsyncResult iar)
        {
            try {
                Socket accepted = listeningSocket.EndAccept(iar);
                if (blockedHosts.Contains((accepted.RemoteEndPoint as IPEndPoint).Address.ToString()))
                {
                    accepted.Disconnect(false);
                    return;
                }
                accepted.NoDelay = true;
                ProtocolClient protocolClient = new ProtocolClient(accepted, ServerOptions.ClientOptions);

                protocolClient.ConnectionError        += ProtocolClient_ConnectionError;
                protocolClient.ConnectionEstablished  += ProtocolClient_ConnectionEstablished;
                protocolClient.PacketReceived         += ProtocolClient_PacketReceived;
                protocolClient.ReceiveProgressChanged += ProtocolClient_ReceiveProgressChanged;
                protocolClient.PacketSend             += ProtocolClient_PacketSend;
                protocolClient.DOSDetected            += ProtocolClient_DOSDetected;
                protocolClient.PingUpdated            += ProtocolClient_PingUpdated;

                protocolClient.Start();
                listeningSocket.BeginAccept(AcceptCallBack, null);
            } catch {
                //MessageBox.Show(ex.Message + " \n\n [" + ex.StackTrace + "]");
            }
        }
示例#4
0
 public void Broadcast(byte[] packet, ProtocolClient exception = null)
 {
     lock (syncLock) {
         for (int i = 0; i > connectedClients.Count; i++)
         {
             var client = connectedClients[i];
             if (client != exception)
             {
                 try {
                     client.Send(packet);
                 } catch { }
             }
         }
     }
 }
示例#5
0
 private void ProtocolClient_PacketReceived(ProtocolClient sender, PacketReceivedEventArgs PacketReceivedEventArgs)
 {
     PacketReceived?.Invoke(sender, PacketReceivedEventArgs);
 }
示例#6
0
 private void ProtocolClient_ReceiveProgressChanged(ProtocolClient sender, int bytesReceived, int bytesToReceive)
 {
     ReceiveProgressChanged?.Invoke(sender, bytesReceived, bytesToReceive);
 }
示例#7
0
 private void ProtocolClient_DOSDetected(ProtocolClient sender)
 {
     DOSDetected?.Invoke(sender);
 }
示例#8
0
 private void ProtocolClient_PacketSend(ProtocolClient sender, int Send)
 {
     PacketSend?.Invoke(sender, Send);
 }
示例#9
0
 private void ProtocolClient_PingUpdated(ProtocolClient sender, double ping)
 {
     PingUpdated?.Invoke(sender, ping);
 }