Esempio n. 1
0
        public int WriteData(byte[] rDataToWrite)
        {
            dataToWrite = rDataToWrite;
            toWrite     = DevComTcpServerDataToWrite.DataReady;

            return(0);
        }
Esempio n. 2
0
        private void handleClientCommunication(object rClient)
        {
            TcpClient client = (TcpClient)(rClient);

            NetworkStream stream = client.GetStream();

            byte[] receiving = new byte[recBufferSize];

            while (true)
            {
                int bytesRead = 0;

                try
                {
                    // blocks until a client sends a message
                    bytesRead = stream.Read(receiving, 0, recBufferSize);
                }
                catch
                {
                    break;                     // Socket error
                }

                if (bytesRead == 0)
                {
                    break;                     // client has disconnected
                }

                byte[] receivedBytes = new byte[bytesRead];

                for (int i = 0; i < bytesRead; i++)
                {
                    receivedBytes[i] = receiving[i];
                }

                recBuffer.AddBytes(receivedBytes);

                // wait for Data to write...
                while (toWrite == DevComTcpServerDataToWrite.Pending)
                {
                }

                if (toWrite == DevComTcpServerDataToWrite.DataReady)
                {
                    // Answer
                    stream.Write(dataToWrite, 0, dataToWrite.Length);
                    stream.Flush();
                }

                toWrite = DevComTcpServerDataToWrite.Pending;                 // set to pending for next cycle...
            }

            client.Close();
        }
Esempio n. 3
0
        private void handleClientCommunication(object rClient)
        {
            TcpClient client = (TcpClient)(rClient);

            NetworkStream stream = client.GetStream();

            byte[] receiving = new byte[recBufferSize];

            while(true)
            {
                int bytesRead = 0;

                try
                {
                    // blocks until a client sends a message
                    bytesRead = stream.Read(receiving,0, recBufferSize);

                }
                catch
                {
                    break; // Socket error
                }

                if(bytesRead == 0)
                {
                    break; // client has disconnected
                }

                byte[] receivedBytes = new byte[bytesRead];

                for(int i=0; i<bytesRead; i++)
                {
                    receivedBytes[i] = receiving[i];
                }

                recBuffer.AddBytes(receivedBytes);

                // wait for Data to write...
                while(toWrite == DevComTcpServerDataToWrite.Pending)
                {

                }

                if(toWrite == DevComTcpServerDataToWrite.DataReady)
                {
                    // Answer
                    stream.Write(dataToWrite,0,dataToWrite.Length);
                    stream.Flush();
                }

                toWrite = DevComTcpServerDataToWrite.Pending; // set to pending for next cycle...
            }

            client.Close();
        }
Esempio n. 4
0
        public int WriteData(byte[] rDataToWrite)
        {
            dataToWrite = rDataToWrite;
            toWrite = DevComTcpServerDataToWrite.DataReady;

            return(0);
        }
Esempio n. 5
0
 public void RemainListening()
 {
     toWrite = DevComTcpServerDataToWrite.NoResponseRequired;
 }
Esempio n. 6
0
 public void RemainListening()
 {
     toWrite = DevComTcpServerDataToWrite.NoResponseRequired;
 }