public override string ToString()
 {
     return(PartitionId.PadRight(3, ' ')
            + "  " + LocalPort.ToString().PadRight(5 + 5, ' ')
            + "  " + ForeignPort.ToString().PadRight(5 + 5, ' ')
            + "  " + ForeignIp.ToString().PadRight(15, ' ')
            + "  " + InboundIBBK.ToString().PadRight(20, ' ')
            + "  " + InboundByte.ToString().PadRight(20, ' ')
            + "  " + InboundIBBKDup.ToString().PadRight(20, ' ')
            + "  " + InboundByteDup.ToString().PadRight(20, ' ')
            + "  " + EfficiencyFormatter(InboundEfficiency).PadRight(6 + 7, ' ')
            + "  " + OutboundIBBK.ToString().PadRight(20, ' ')
            + "  " + OutboundByte.ToString().PadRight(20, ' ')
            + "  " + OutboundIBBKDup.ToString().PadRight(20, ' ')
            + "  " + OutboundByteDup.ToString().PadRight(20, ' ')
            + "  " + EfficiencyFormatter(OutboundEfficiency).PadRight(6 + 8, ' ')
            + "  " + RcvdSocket.ToString().PadRight(20, ' ')
            + "  " + MaxRecvWindow.ToString().PadRight(10 + 3, ' ')
            + "  " + RecvWindowClosed.ToString().PadRight(20, ' ')
            + "  " + SendSocket.ToString().PadRight(20, ' ')
            + "  " + MaxSendWindow.ToString().PadRight(10 + 3, ' ')
            + "  " + Retransmitted.ToString().PadRight(20, ' ')
            + "  " + InRetransmitMode.ToString().PadRight(20, ' ')
            + "  " + HighestDepth.ToString().PadRight(20, ' ')
            + "  " + Sws.ToString().PadRight(20, ' ')
            + "  " + ProtocolFormatter(Protocol, FlagAA).PadRight(8, ' ')
            + "  " + LocalCallFormatter(localCall).PadRight(3 + 4, ' ')
            + "  " + StateFormatter(state).PadRight(12, ' ')
            + "  " + StartTime.ToString().PadRight(22, ' ')
            + "  " + EndTime.ToString().PadRight(22, ' '));
 }
Exemple #2
0
        public Form1()
        {
            InitializeComponent();
            //Создание API для общения с сервером
            SendSocket sendSocket = new SendSocket("127.0.0.1", 8001);

            api = new ConveyorApi(sendSocket);
            TryConnect();
        }
Exemple #3
0
        public PluginClient(int sendPort, int receivePort)
        {
            _sendSocket                     = new SendSocket(HostName, sendPort);
            _receiveSocket                  = new ReceiveSocket(HostName, receivePort);
            _sendSocket.Connection         += connected => SocketConnectionHandler(_sendSocket, connected);
            _receiveSocket.Connection      += connected => SocketConnectionHandler(_receiveSocket, connected);
            _receiveSocket.MessageReceived += ReceiveSocketOnMessageReceived;

            _eventProcessingThread = new ProcessingThread("PluginClient Event Processing thread", EventProcessingIteration);
        }
Exemple #4
0
        public void TestServerLogger()
        {
            SendSocket s = new SendSocket();

            s.Connect(serverIp, serverPort, localPort);
            s.Send("HELLO WORLD!");
            s.Send("CAN YOU HEAR ME?");

            System.Threading.Thread.Sleep(4000);

            s.Send("HELLO..?");
        }
Exemple #5
0
 public PushPullSocketPortSpecs()
 {
     Context1    = NetMQContext.Create();
     Context2    = NetMQContext.Create();
     RcvdSignal  = new ManualResetEvent(false);
     ClientFiber = PoolFiber.StartNew();
     Pull        = new PullSocket <string>(Context1, "tcp://localhost:6002", x => Encoding.Unicode.GetString(x), Channel);
     Push        = new SendSocket <string>(Context2,
                                           "tcp://localhost:6002",
                                           s => Encoding.Unicode.GetBytes(s),
                                           ZmqSocketType.Push,
                                           false);
 }
 public PushPullSocketPortSpecs()
 {
     Context1 = NetMQContext.Create();
     Context2 = NetMQContext.Create();
     RcvdSignal = new ManualResetEvent(false);
     ClientFiber = PoolFiber.StartNew();
     Pull = new PullSocket<string>(Context1, "tcp://localhost:6002", x => Encoding.Unicode.GetString(x), Channel);
     Push = new SendSocket<string>(Context2,
         "tcp://localhost:6002",
         s => Encoding.Unicode.GetBytes(s),
         ZmqSocketType.Push,
         false);
 }
Exemple #7
0
 public PubSubSpecs()
 {
     ClientFiber = PoolFiber.StartNew();
     Context1    = NetMQContext.Create();
     Send        = new SendSocket <string>(Context1,
                                           "tcp://localhost:6001",
                                           s => Encoding.Unicode.GetBytes(s));
     Context2   = NetMQContext.Create();
     RcvdSignal = new ManualResetEvent(false);
     Subscriber = new SubscribeSocket <string>(Context2,
                                               "tcp://localhost:6001",
                                               x => Encoding.Unicode.GetString(x),
                                               Channel);
     Subscriber.SubscribeAll();
 }
Exemple #8
0
 public PubSubSpecs()
 {
     ClientFiber = PoolFiber.StartNew();
     Context1 = NetMQContext.Create();
     Send = new SendSocket<string>(Context1,
         "tcp://localhost:6001",
         s => Encoding.Unicode.GetBytes(s));
     Context2 = NetMQContext.Create();
     RcvdSignal = new ManualResetEvent(false);
     Subscriber = new SubscribeSocket<string>(Context2,
         "tcp://localhost:6001",
         x => Encoding.Unicode.GetString(x),
         Channel);
     Subscriber.SubscribeAll();
 }
Exemple #9
0
        public void ErrorConnect()
        {
            SendSocket SendSocket = new SendSocket(address3, port3);

            try
            {
                SendSocket.SendMessage(new byte[] { 1, 2 }, 2);
            }
            catch
            {
                return;
            }

            Assert.Fail();
        }
Exemple #10
0
        public void TestReadTask()
        {
            SendSocket sSock = new SendSocket();

            sSock.Connect(localhost, recvPort, sendPort);

            RecvSocket rSock = new RecvSocket();

            rSock.Connect(recvPort);
            rSock.BeginRead();

            for (int i = 0; i < 10; ++i)
            {
                System.Threading.Thread.Sleep(1000);
                SendString(sSock, String.Format("{0} : Hello World", i));
            }
        }
Exemple #11
0
        public void TestStopRead()
        {
            SendSocket sSock = new SendSocket();

            sSock.Connect(localhost, recvPort, sendPort);

            RecvSocket rSock = new RecvSocket();

            rSock.Connect(recvPort);
            rSock.BeginRead();

            for (int i = 1; i < 11; ++i)
            {
                System.Threading.Thread.Sleep(1000);
                // kill read half way through
                if (i % 5 == 0)
                {
                    rSock.EndRead();
                }
                SendString(sSock, String.Format("{0} : Hello World", i));
            }
        }
Exemple #12
0
        // Main thread for sending telegrams
        private void SendThreading()
        {
            TelegramACK telAck = null;

            try
            {
                if (SimulateMFCS)
                {
                    SendListener = new TcpListener(SendIPEndPoint);
                    Log.AddLog(Log.Severity.EVENT, Name, "Communication.SendThreading", SendIPEndPoint.ToString());
                    SendListener.Start();
                }

                lock (_lockSendTelegram)
                {
                    SendTelegrams.RemoveAll(p => p.CommSendStatus >= Telegram.CommSendStatusEnum.Ack);
                }

                LastSendTime = DateTime.Now;

                while (Thread.CurrentThread.ThreadState == ThreadState.Background)
                {
                    try
                    {
                        Telegram tel = null;
                        lock (_lockSendTelegram)
                            tel = SendTelegrams.FirstOrDefault(prop => prop.CommSendStatus < Telegram.CommSendStatusEnum.Ack);
                        if (DateTime.Now - LastSendTime > SendTimeOut)
                        {
                            InitSendSocket();
                            if (tel != null)
                            {
                                tel.CommSendStatus = Telegram.CommSendStatusEnum.None;
                            }
                            LastSendTime = DateTime.Now;
                            Retry        = 0;
                            Log.AddLog(Log.Severity.EVENT, Name, "Communication.SendThread", "Send timeout, SendSocket reinitialized!");
                        }
                        else if (DateTime.Now - LastSendTime > KeepALifeTime && tel == null)
                        {
                            Telegram tRes = null;
                            lock (_lockSendTelegram)
                                tRes = SendTelegrams.FirstOrDefault(prop => prop.CommSendStatus < Telegram.CommSendStatusEnum.Ack);
                            if (tRes == null)
                            {
                                if (KeepALifeTelegram != null)
                                {
                                    Telegram t = Activator.CreateInstance(KeepALifeTelegram.GetType()) as Telegram;
                                    t.Sender   = MFCS_ID;
                                    t.Receiver = PLC_ID;
                                    t.Build();
                                    AddSendTelegram(t);
                                    Log.AddLog(Log.Severity.EVENT, Name, "Communication.SendThread", String.Format("Adding KeepALife telegram"));
                                }
                            }
                        }
                        else if (!SendSocket.Connected)
                        {
                            InitSendSocket();
                            ConnectSendPartner();
                        }
                        else if (tel != null)
                        {
                            switch (tel.CommSendStatus)
                            {
                            case (Telegram.CommSendStatusEnum.None):
                                tel.Sequence = Sequence;
                                tel.Build();
                                // Log.AddLog(Log.Severity.EVENT, Name, "Communication.SendThread", String.Format("Start sending {0}", tel.ToString()));
                                SendSocket.Send(tel.ByteBuffer, tel.Length, SocketFlags.None);
                                Log.AddLog(Log.Severity.EVENT, Name, "Communication.SendThread", String.Format("Sended {0}", tel.ToString()));
                                tel.CommSendStatus = Telegram.CommSendStatusEnum.WaitACK;
                                telAck             = new TelegramACK();
                                SendTime           = DateTime.Now;
                                break;

                            case (Telegram.CommSendStatusEnum.WaitACK):
                                int numRead = 0;
                                do
                                {
                                    numRead += SendSocket.Receive(telAck.ByteBuffer, numRead, telAck.ByteBuffer.Length - numRead, SocketFlags.None);
                                } while (numRead < telAck.ByteBuffer.Length);
                                telAck.ReadBuffer();
                                Log.AddLog(Log.Severity.EVENT, Name, "Communication.SendThread", String.Format("Received ACK {0}", telAck.ToString()));
                                if (telAck.Validate() && telAck.Sequence == tel.Sequence)
                                {
                                    tel.CommSendStatus = Telegram.CommSendStatusEnum.Ack;
                                    LastSendTime       = DateTime.Now;
                                    Retry = 0;
                                    if (Sequence < 99)
                                    {
                                        Sequence++;
                                    }
                                    else
                                    {
                                        Sequence = 0;
                                    }
                                    Log.AddLog(Log.Severity.EVENT, Name, "Communication.SendThreading", String.Format("Send Finished : {0}", tel.ToString()));
                                    NotifySend(tel);
                                }
                                else
                                {
                                    //                                      tel.CommSendStatus = Telegram.CommSendStatusEnum.None;
                                    Retry++;
                                    Log.AddLog(Log.Severity.EVENT, Name, "Communication.SendThreading", String.Format("Retry increased - {0}", Retry));
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            Thread.Sleep(100);
                        }
                    }
                    catch (SocketException ex)
                    {
                        Log.AddLog(Log.Severity.EXCEPTION, Name, "Communication.SendThread::SocketException", ex.Message);
                        Thread.Sleep(1000);
                    }
                }
                catch (TelegramException ex)
                {
                    Log.AddLog(Log.Severity.EXCEPTION, Name, "Communication.SendThread::TelegramException", ex.Message);
                    Thread.Sleep(1000);
                }
                catch (ThreadAbortException ex)
                {
                    Log.AddLog(Log.Severity.EXCEPTION, Name, "Communication.RcvThreading::Communication", ex.Message);
                    return;
                }
                catch (CommunicationException ex)
                {
                    Log.AddLog(Log.Severity.EXCEPTION, Name, "Communication.SendThread::CommunicationException", ex.Message);
                    Thread.Sleep(1000);
                }
            }
Exemple #13
0
        // Main thread for receiving telegrams
        private void RcvThreading()
        {
            try
            {
                if (SimulateMFCS)
                {
                    RcvListener = new TcpListener(RcvIPEndPoint);
                    Log.AddLog(Log.Severity.EVENT, Name, "Communication.RcvThreading", RcvIPEndPoint.ToString());
                    RcvListener.Start();
                }


                LastReceiveTime = DateTime.Now;

                while (Thread.CurrentThread.ThreadState == ThreadState.Background)
                {
                    try
                    {
                        RcvTelegrams.RemoveAll(p => p.CommRcvStatus >= Telegram.CommRcvStatusEnum.NotifyDone);
                        if (DateTime.Now - LastReceiveTime > RcvTimeOut)
                        {
                            InitRcvSocket();
                            LastReceiveTime = DateTime.Now;
                            Log.AddLog(Log.Severity.EVENT, Name, "Communication.RcvThreading", "Timeout receiving");
                        }
                        else if (DateTime.Now - LastNotifyTime > RefreshTime)
                        {
                            LastNotifyTime = DateTime.Now;
                            Log.AddLog(Log.Severity.EVENT, Name, "Communication.RcvThreading", "Refresh() is called");
                            OnRefresh.ForEach(prop => prop?.Invoke());
                        }
                        else if (!RcvSocket.Connected)
                        {
                            InitRcvSocket();
                            ConnectRcvPartner();
                        }
                        else
                        {
                            if (RcvSocket.Available == 0)
                            {
                                Thread.Sleep(1);
                            }
                            else
                            {
                                Telegram tel     = new TelegramOnlyHeader();
                                int      numRead = 0;
                                do
                                {
                                    numRead += RcvSocket.Receive(tel.ByteBuffer, numRead, tel.ByteBuffer.Length - numRead, SocketFlags.None);
                                } while (numRead < tel.ByteBuffer.Length);
                                // Log.AddLog(Log.Severity.EVENT, Name, "Communication.RcvThreading", String.Format("Received {0} bytes", numRead));
                                tel.ReadBuffer();
                                tel.Validate(false);
                                Telegram tel1 = Activator.CreateInstance(AllTelegrams[tel.TelType].GetType()) as Telegram;
                                tel.ByteBuffer.CopyTo(tel1.ByteBuffer, 0);
                                if (tel1.DesignLength() - tel.DesignLength() > 0 && tel.TelCode == 0)
                                {
                                    numRead = 0;
                                    do
                                    {
                                        numRead += RcvSocket.Receive(tel1.ByteBuffer, tel.DesignLength() + numRead, tel1.DesignLength() - tel.DesignLength() - numRead, SocketFlags.None);
                                    } while (numRead < tel1.DesignLength() - tel.DesignLength());
                                    // Log.AddLog(Log.Severity.EVENT, Name, "Communication.RcvThreading", String.Format("Received {0} bytes", numRead));
                                }
                                tel1.ReadBuffer();
                                tel1.Validate();
                                NotifyRcv(tel1);
                                TelegramACK telACK = new TelegramACK();
                                telACK.Sequence = tel.Sequence;
                                telACK.TelCode  = (System.UInt16) 0xFFFF;
                                telACK.TelType  = tel.TelType;
                                telACK.Sender   = tel.Receiver;
                                telACK.Receiver = tel.Sender;
                                telACK.Build();
                                RcvSocket.Send(telACK.ByteBuffer);
                                Log.AddLog(Log.Severity.EVENT, Name, "Communication.RcvThreading", String.Format("ACK sended {0}", telACK.ToString()));
                                tel1.CommRcvStatus = Telegram.CommRcvStatusEnum.Ack;
                                RcvTelegrams.Add(tel1);
                                LastReceiveTime = DateTime.Now;
                                LastNotifyTime  = DateTime.Now;
                                Log.AddLog(Log.Severity.EVENT, Name, "Communication.RcvThreading", String.Format("Received finished : {0}", tel1.ToString()));
                            }
                        }
                    }
                    catch (SocketException ex)
                    {
                        Log.AddLog(Log.Severity.EXCEPTION, Name, "Communication.RcvThreading::Socket", ex.Message);
                        Thread.Sleep(1000);
                    }
                    catch (TelegramException ex)
                    {
                        Log.AddLog(Log.Severity.EXCEPTION, Name, "Communication.RcvThreading::Telegram", ex.Message);
                        Thread.Sleep(1000);
                    }
                    catch (KeyNotFoundException ex)
                    {
                        Log.AddLog(Log.Severity.EXCEPTION, Name, "Communication.RcvThreading::KeyNotFound", ex.Message);
                        Thread.Sleep(1000);
                    }
                    catch (CommunicationException ex)
                    {
                        Log.AddLog(Log.Severity.EXCEPTION, Name, "Communication.RcvThreading::Communication", ex.Message);
                        Thread.Sleep(1000);
                    }
                    catch (ThreadAbortException ex)
                    {
                        Log.AddLog(Log.Severity.EXCEPTION, Name, "Communication.RcvThreading::Communication", ex.Message);
                        return;
                    }
                    catch (Exception ex)
                    {
                        Log.AddLog(Log.Severity.EXCEPTION, Name, "Communication.SendThread::unknown", ex.Message);
                        Thread.Sleep(1000);
                    }
                }
            }
            finally
            {
                RcvSocket.Close();
                RcvSocket.Dispose();
                SendSocket.Close();
                SendSocket.Dispose();
            }
        }
Exemple #14
0
 public void CreateSendSocket()
 {
     SendSocket sendSocket = new SendSocket(address, port);
 }
Exemple #15
0
 // sends a string lol
 private void SendString(SendSocket sendSock, string message)
 {
     sendSock.Send(message);
 }
Exemple #16
0
 /// <summary>
 /// Создание новго АПИ для работы с конвеером
 /// </summary>
 /// <param name="SendSocket">Сокет, через который происходит связь с сервером</param>
 public ConveyorApi(SendSocket SendSocket)
 {
     sendSocket = SendSocket;
     InitialCommand();
 }
Exemple #17
0
        // notify about new received telegram


        // Main thread for receiving telegrams
        public override void RcvThreading()
        {
            try
            {
                LastReceiveTime = DateTime.Now;

                // initialize from this thread

                while (Thread.CurrentThread.ThreadState == ThreadState.Background)
                {
                    try
                    {
                        lock (_lockRcvTelegram)
                            RcvTelegrams.RemoveAll(p => p.CommRcvStatus >= Telegram.CommRcvStatusEnum.NotifyDone);
                        if (DateTime.Now - LastReceiveTime > RcvTimeOut)
                        {
                            InitRcvSocket();
                            LastReceiveTime = DateTime.Now;
                            Log?.AddLog(Log.Severity.EXCEPTION, Name, "Communicator.RcvThreading", "Timeout receiving");
                        }
                        else if (DateTime.Now - LastNotifyTime > RefreshTime)
                        {
                            LastNotifyTime = DateTime.Now;
                            Log?.AddLog(Log.Severity.EVENT, Name, "Communicator.RcvThreading", "Refresh() is called");
                            CallRefresh();
                        }
                        else if (!RcvSocket.Connected)
                        {
                            InitRcvSocket();
                            ConnectRcvPartner();
                        }
                        else
                        {
                            if (RcvSocket.Available == 0)
                            {
                                Thread.Sleep(1);
                            }
                            else
                            {
                                Telegram tel     = new TelegramOnlyHeader();
                                int      numRead = 0;
                                int      crRead  = 0;
                                do
                                {
                                    crRead   = RcvSocket.Receive(tel.ByteBuffer, numRead, tel.ByteBuffer.Length - numRead, SocketFlags.None);
                                    numRead += crRead;
                                    if (crRead == 0)
                                    {
                                        throw new TelegramException("Receive bytes is 0.");
                                    }
                                } while (numRead < tel.ByteBuffer.Length);
                                // Log?.AddLog(Log.Severity.EVENT, Name, "Communication.RcvThreading", String.Format("Received {0} bytes", numRead));
                                tel.ReadBuffer();
                                tel.Validate(false);
                                Telegram tel1 = Activator.CreateInstance(AllTelegrams[tel.TelType].GetType()) as Telegram;
                                tel.ByteBuffer.CopyTo(tel1.ByteBuffer, 0);
                                if (tel1.DesignLength() - tel.DesignLength() > 0 && tel.TelCode == 0)
                                {
                                    numRead = 0;
                                    crRead  = 0;
                                    do
                                    {
                                        crRead   = RcvSocket.Receive(tel1.ByteBuffer, tel.DesignLength() + numRead, tel1.DesignLength() - tel.DesignLength() - numRead, SocketFlags.None);
                                        numRead += crRead;
                                        if (crRead == 0)
                                        {
                                            throw new TelegramException("Receive bytes is 0.");
                                        }
                                    } while (numRead < tel1.DesignLength() - tel.DesignLength());
                                    // Log?.AddLog(Log.Severity.EVENT, Name, "Communication.RcvThreading", String.Format("Received {0} bytes", numRead));
                                }
                                tel1.ReadBuffer();
                                tel1.Validate();
                                NotifyRcv(tel1);
                                TelegramACK telACK = new TelegramACK();
                                telACK.Sequence = tel.Sequence;
                                telACK.TelCode  = (System.UInt16) 0xFFFF;
                                telACK.TelType  = tel.TelType;
                                telACK.Sender   = tel.Receiver;
                                telACK.Receiver = tel.Sender;
                                telACK.Build();
                                RcvSocket.Send(telACK.ByteBuffer);
                                tel1.CommRcvStatus = Telegram.CommRcvStatusEnum.NotifyDone;
                                LastReceiveTime    = DateTime.Now;
                                LastNotifyTime     = DateTime.Now;
                                Log?.AddLog(Log.Severity.EVENT, Name, "Communicator.RcvThreading", String.Format("Received finished : {0}", tel1.ToString()));
                            }
                        }
                    }
                    catch (SocketException ex)
                    {
                        Log?.AddLog(Log.Severity.EXCEPTION, Name, "Communicator.RcvThreading::SocketException", ex.Message);
                        Thread.Sleep(1000);
                    }
                    catch (TelegramException ex)
                    {
                        Log?.AddLog(Log.Severity.EXCEPTION, Name, "Communicator.RcvThreading::TelegramException", ex.Message);
                        Thread.Sleep(1000);
                    }
                    catch (KeyNotFoundException ex)
                    {
                        Log?.AddLog(Log.Severity.EXCEPTION, Name, "Communicator.RcvThreading::KeyNotFound", ex.Message);
                        Thread.Sleep(1000);
                    }
                    catch (CommunicationException ex)
                    {
                        Log?.AddLog(Log.Severity.EXCEPTION, Name, "Communicator.RcvThreading::CommunicationException", ex.Message);
                        Thread.Sleep(1000);
                    }
                    catch (ThreadAbortException ex)
                    {
                        Log?.AddLog(Log.Severity.EXCEPTION, Name, "Communicator.RcvThreading::ThreadAbortException", ex.Message);
                        return;
                    }
                    catch (ServiceCommunicatorException ex)
                    {
                        Log?.AddLog(Log.Severity.EXCEPTION, Name, "Communicator.RcvThreading::ServiceCommunicationException", ex.Message);
                        Thread.Sleep(3000);
                    }
                    catch (Exception ex)
                    {
                        Log?.AddLog(Log.Severity.EXCEPTION, Name, "Communicator.SendThread::Exception", ex.Message);
                        Thread.Sleep(1000);
                    }
                }
            }
            finally
            {
                RcvSocket.Close();
                RcvSocket.Dispose();
                SendSocket.Close();
                SendSocket.Dispose();
            }
        }