Exemplo n.º 1
0
 public void Send(string sessionId, ScadaTCPMsg msg, bool closeClient)
 {
     try
     {
         // Convert the string data to byte data using ASCII encoding.
         //            byte[] byteData = Encoding.ASCII.GetBytes(data);
         if (string.IsNullOrEmpty(sessionId))
         {
             throw new Exception("Session id is null!");
         }
         ScadaClient client = ScadaTCPClients.GetClient(sessionId);
         if (client == null)
         {
             throw new Exception("Not found client by session:" + sessionId);
         }
         LOG.DebugFormat("({2}) Send {0} bytes to {1}", msg.MsgBytes.Length, client.socket.RemoteEndPoint, Name);
         if (PrintSendHex)
         {
             PrintUtils.PrintHex(msg.MsgBytes);
         }
         SendState state = new SendState();
         state.CloseClient  = closeClient;
         state.RemoteSocket = client.socket;
         state.Client       = client;
         state.Msg          = msg;
         // Begin sending the data to the remote device.
         client.socket.BeginSend(msg.MsgBytes, 0, msg.MsgBytes.Length, 0,
                                 new AsyncCallback(SendCallback), state);
     }
     catch (Exception e)
     {
         ReadException(e, null);
     }
 }
Exemplo n.º 2
0
        public void Send(string sessionId, string msg, bool closeClient)
        {
            if (string.IsNullOrEmpty(sessionId))
            {
                throw new Exception("Session id is null!");
            }
            ScadaClient client = ScadaTCPClients.GetClient(sessionId);

            if (client == null)
            {
                throw new Exception("Not found client by session:" + sessionId);
            }
            LOG.DebugFormat("({2}) Send {0} bytes to {1}", msg.Length, client.socket.RemoteEndPoint, Name);
            if (PrintSendHex)
            {
                PrintUtils.PrintHex(msg);
            }
            SendState state = new SendState();

            state.CloseClient  = closeClient;
            state.RemoteSocket = client.socket;
            state.Client       = client;
            state.MsgBits      = Encoding.ASCII.GetBytes(msg);
            // Begin sending the data to the remote device.
            client.socket.BeginSend(state.MsgBits, 0, state.MsgBits.Length, 0,
                                    new AsyncCallback(SendCallback), state);
        }