private void Handler()
        {
            Console.WriteLine("Client thread has started");
            byte[]        bytesFrom     = new byte[clientSocket.ReceiveBufferSize];
            NetworkStream networkStream = clientSocket.GetStream();

            networkStream.Read(bytesFrom, 0, clientSocket.ReceiveBufferSize);
            Flux flux = Flux.DeSerialize(bytesFrom);

            Console.WriteLine("Recieved flux has been deserialized");
            object result = executor.Execute(adapter.GenerateInstance(flux.ReadData()));

            Console.WriteLine("Command has been executed");
            flux.WriteData(ObjectToBytes(result));
            byte[] sendBytes = Flux.Serialize(flux);
            networkStream.Write(sendBytes, 0, sendBytes.Length);
            Console.WriteLine("Response has been sent");
            networkStream.Flush();
            clientSocket.Close();
            Console.WriteLine("Socket has been closed");
        }
예제 #2
0
        public Flux Send(Flux flux, List <object> parameters)
        {
            byte[]      bytes      = new byte[100000];
            IPHostEntry ipHostInfo = Dns.GetHostEntry((string)parameters[0]);
            IPAddress   ipAddress  = ipHostInfo.AddressList[0];
            IPEndPoint  remoteEP   = new IPEndPoint(ipAddress, (int)parameters[1]);
            Socket      client     = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                client.Connect(remoteEP);
                int bytesSent = client.Send(Flux.Serialize(flux));
                int bytesRec  = client.Receive(bytes);
                flux = Flux.DeSerialize(bytes);
                client.Shutdown(SocketShutdown.Both);
                client.Close();
                return(flux);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected exception : {0}", e.ToString());
                return(null);
            }
        }