public NetworkServerClientWorker(TimeSpan requiredLatency, NetworkClientBase clientToAttach)
     : base(clientToAttach.ClientEndPointsLink.ToString(), requiredLatency)
 {
     client = clientToAttach;
     client.OnClientEvent += new NetworkClientBase.DelegateClientEventMethod(client_OnClientEvent);
     enable = true;
 }
 //object locker = new object();
 void clientbase_OnClientEvent(NetworkClientBase.ClientEventTypeEnum EventType, object EventData)
 {
     //lock (locker)
     //{
         switch (EventType)
         {
             case NetworkClientBase.ClientEventTypeEnum.Connected:
                 isConnected = true;
                 break;
             case NetworkClientBase.ClientEventTypeEnum.MessageRecieved:
                 break;
             case NetworkClientBase.ClientEventTypeEnum.MessageSent:
                 packetsSent++;
                 break;
             case NetworkClientBase.ClientEventTypeEnum.Disconnected:
                 isConnected = false;
                 break;
             case NetworkClientBase.ClientEventTypeEnum.RemoteSideDisconnected:
                 break;
             case NetworkClientBase.ClientEventTypeEnum.Error:
                 break;
         }
     //}
     if (OnClientEvent != null) OnClientEvent(EventType, EventData, this);
 }
 public NetworkServerClientWorker(IPEndPoint targetEndPoint, TimeSpan requiredLatency,
     CommunicationSettings workerCommunicationSettings)
     : base(new EndPointsLink(new IPEndPoint(IPAddress.None,0),targetEndPoint).ToString(), requiredLatency)
 {
     client = new NetworkClientBase(workerCommunicationSettings);
     client.OnClientEvent += new NetworkClientBase.DelegateClientEventMethod(client_OnClientEvent);
     enable = true;
 }
 public override void client_OnClientEvent(NetworkClientBase.ClientEventTypeEnum EventType, object EventData)
 {
     if (EventType == NetworkClientBase.ClientEventTypeEnum.Accepted)
     {
         NetworkServerClientAccepter nsca =
             new NetworkServerClientAccepter(RequiredLatency, (NetworkClientBase)EventData);
         EventData = nsca;
     }
     base.client_OnClientEvent(EventType, EventData);
 }
 public IdentityClient()
 {
     clientbase = new NetworkClientBase(
         new CommunicationSettings(
         CommunicationSettings.SocketOperationFlow.Asynchronic,
         CommunicationSettings.SocketOperationFlow.Asynchronic,
         CommunicationSettings.SocketOperationFlow.Asynchronic,
         CommunicationSettings.SocketOperationFlow.Asynchronic,
         CommunicationSettings.SocketOperationFlow.Asynchronic, true));
     clientbase.OnClientEvent +=
         new NetworkClientBase.DelegateClientEventMethod(clientbase_OnClientEvent);
 }
 public NetworkServerClientAccepter(TimeSpan requiredLatency, NetworkClientBase clientToAttach)
     : base(requiredLatency, clientToAttach,
     new CommunicationSettings(
     CommunicationSettings.SocketOperationFlow.Synchronic,
     CommunicationSettings.SocketOperationFlow.Synchronic,
     CommunicationSettings.SocketOperationFlow.Synchronic,
     CommunicationSettings.SocketOperationFlow.Synchronic,
     CommunicationSettings.SocketOperationFlow.Synchronic, false, 256))
 {
     //Auto enable this client - so it will not disconnect on first work iteration.
     enable = true;
 }
Exemple #7
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            btnConnect.Enabled = false;

            chatClient =
                new NetworkClientBase(
                new CommunicationSettings(
                CommunicationSettings.SocketOperationFlow.Asynchronic,
                CommunicationSettings.SocketOperationFlow.Asynchronic,
                CommunicationSettings.SocketOperationFlow.Asynchronic,
                CommunicationSettings.SocketOperationFlow.Asynchronic,
                CommunicationSettings.SocketOperationFlow.Asynchronic, true));

            chatClient.OnClientEvent += chatClient_OnClientEvent;

            chatClient.Connect(
                new System.Net.IPEndPoint(System.Net.IPAddress.Loopback, 3456));

            btnDisconnect.Enabled = true;
        }
Exemple #8
0
 void chatClient_OnClientEvent(NetworkClientBase.ClientEventTypeEnum EventType, object EventData)
 {
     switch (EventType)
     {
         case NetworkClientBase.ClientEventTypeEnum.None:
             break;
         case NetworkClientBase.ClientEventTypeEnum.Accepted:
             break;
         case NetworkClientBase.ClientEventTypeEnum.Connected:
             chatClient.Recieve();
             break;
         case NetworkClientBase.ClientEventTypeEnum.RawDataRecieved:
             break;
         case NetworkClientBase.ClientEventTypeEnum.MessageRecieved:
             txtbxChatData.BeginInvoke(
                 new dlgUpdater(updateChatData),
                 System.Text.Encoding.Unicode.GetString((byte[])EventData));
             chatClient.Recieve();
             break;
     }
 }
        private void skt_OnSocketEvent(NetworkSocketManagerTCP.SocketEventTypeEnum EventType, object EventData)
        {
            switch (EventType)
            {
                case NetworkSocketManagerTCP.SocketEventTypeEnum.None:
                    if (OnClientEvent != null)
                        OnClientEvent.BeginInvoke(ClientEventTypeEnum.None, EventData, null, null);
                    break;
                case NetworkSocketManagerTCP.SocketEventTypeEnum.Connected:
                    if (OnClientEvent != null)
                        OnClientEvent.BeginInvoke(ClientEventTypeEnum.Connected, EventData, null, null);
                    break;
                case NetworkSocketManagerTCP.SocketEventTypeEnum.Accepted:
                    if (OnClientEvent != null)
                    {
                        NetworkClientBase nwcbAccepter =
                            new NetworkClientBase((NetworkSocketManagerTCP)EventData);
                        OnClientEvent.BeginInvoke(ClientEventTypeEnum.Accepted, nwcbAccepter, null, null);
                    }
                    break;
                case NetworkSocketManagerTCP.SocketEventTypeEnum.DataSent:
                    if (OnClientEvent != null)
                        OnClientEvent.BeginInvoke(ClientEventTypeEnum.MessageSent, EventData, null, null);
                    break;
                case NetworkSocketManagerTCP.SocketEventTypeEnum.DataRecieved:
                    if (((byte[])EventData).Length > 0)
                    {
                        if (OnClientEvent != null)
                            OnClientEvent.BeginInvoke(ClientEventTypeEnum.RawDataRecieved,
                               ((byte[])EventData), null, null);

                        incommingData = ByteArrayOperations.AddByteArrays(incommingData, (byte[])EventData);
                        byte[] data = null;
                        while (ApplicationLayerTransmitionControl.IsIntegratedDataWaiting(incommingData))
                        {
                            data = ApplicationLayerTransmitionControl.
                                ExtractIntegratedDataFromBuffer(ref incommingData);
                            if (OnClientEvent != null)
                                OnClientEvent.BeginInvoke(ClientEventTypeEnum.MessageRecieved,
                                          data, null, null);
                        }
                        if (incommingData.Length > 0) Recieve();
                    }
                    else if (OnClientEvent != null)
                        OnClientEvent.BeginInvoke(ClientEventTypeEnum.Disconnected, EventData, null, null);
                    break;
                case NetworkSocketManagerTCP.SocketEventTypeEnum.Disconnected:
                    skt.Dispose();
                    if (OnClientEvent != null)
                        OnClientEvent.BeginInvoke(ClientEventTypeEnum.Disconnected, EventData, null, null);
                    break;
                case NetworkSocketManagerTCP.SocketEventTypeEnum.RemoteSideDisconnected:
                    Disconnect();
                    if (OnClientEvent != null)
                        OnClientEvent.BeginInvoke(ClientEventTypeEnum.RemoteSideDisconnected, EventData, null, null);
                    break;
                case NetworkSocketManagerTCP.SocketEventTypeEnum.Error:
                    if (OnClientEvent != null)
                        OnClientEvent.BeginInvoke(ClientEventTypeEnum.Error, EventData, null, null);
                    break;
            }
        }
Exemple #10
0
 void frmMain_OnClientEvent(NetworkClientBase.ClientEventTypeEnum EventType, object EventData,
     IdentityClient Identity)
 {
     switch (EventType)
     {
         case NetworkClientBase.ClientEventTypeEnum.None:
             break;
         case NetworkClientBase.ClientEventTypeEnum.Accepted:
             break;
         case NetworkClientBase.ClientEventTypeEnum.Connected:
             bm_clients_Connected++;
             Identity.clientbase.Recieve();
             break;
         case NetworkClientBase.ClientEventTypeEnum.RawDataRecieved:
             bm_clients_RawDataRecieved++;
             break;
         case NetworkClientBase.ClientEventTypeEnum.MessageRecieved:
             bm_clients_MessagesRecieved++;
             Identity.clientbase.Recieve();
             break;
         case NetworkClientBase.ClientEventTypeEnum.MessageSent:
             bm_clients_MessagesSent++;
             break;
         case NetworkClientBase.ClientEventTypeEnum.RemoteSideDisconnected:
             bm_clients_RemoteDisconnections++;
             break;
         case NetworkClientBase.ClientEventTypeEnum.Disconnected:
             bm_clients_Disconnections++;
             break;
         case NetworkClientBase.ClientEventTypeEnum.Error:
             bm_clients_Errors++;
             break;
     }
 }
 public NetworkClientNotification(
     NetworkClientBase.ClientEventTypeEnum eventType,object eventData)
 {
     this.eventType = eventType;
     this.eventData = eventData;
 }
 public virtual void client_OnClientEvent(NetworkClientBase.ClientEventTypeEnum EventType, object EventData)
 {
     RaiseWorkerNotification(this, new NetworkClientNotification(EventType, EventData));
 }