Ejemplo n.º 1
0
        public static void Send(MemoryStream binaryStream, byte sendingEvent)
        {
            TcpClient client = null;

            try
            {
                //IPAddress address = IPAddress.Parse("192.168.0.37");
                IPAddress  address = IPReceiver.GetIP();
                IPEndPoint ipPoint = new IPEndPoint(address, 8005);

                client = new TcpClient();
                client.Connect(ipPoint);

                using (MemoryStream ms = new MemoryStream())
                {
                    binaryStream.CopyTo(ms);
                    byte[] messsize      = BitConverter.GetBytes(ms.Length);
                    byte[] receivedEvent = new byte[1];
                    receivedEvent[0] = sendingEvent;
                    NetworkStream ns = client.GetStream();
                    ns.Write(receivedEvent, 0, 1);
                    ns.Write(messsize, 0, messsize.Length);
                    ms.Position = 0;
                    ms.CopyTo(ns);
                }
                client.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }
Ejemplo n.º 2
0
 protected override void OnStart()
 {
     IPReceiver receiver = new IPReceiver();
     // Handle when your app starts
 }