public void HandleImageMessageReceived(uint connecitonID, byte[] messageData)
 {
     if(_mediaConsumer != null)
     {
         if (connecitonID == _mediaProvider.ConnectionID)
         {
             TCPRemoteClient client;
             if (false == _server.GetTCPRemoteClient(_mediaConsumer.ConnectionID, out client))
             {
                 Log.error("Failed to get media consumer remote client.");
             }
             else
             {
                 TCPSendPackage sendPackage = new TCPSendPackage();
                 sendPackage.Data = messageData;
                 client.Send(sendPackage);
             }
         }
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            LogHandler myLogHandler = new LogHandler();

            myLogHandler.StartUp();

            ReceiveHandler handler = new ReceiveHandler();
            Console.WriteLine("Server has started.");
            TCPServer server = new TCPServer("10.211.55.3", 6666);

            server.Register(handler);
            if(false == server.Start())
            {
                Log.info("Server failed to start.");
                for (; ; ) ;
            }

            for (; ; )
            {
                TCPSendPackage message = new TCPSendPackage();
                Console.ReadLine();
                Encoding ascii = Encoding.ASCII;
                Encoding unicode = Encoding.Unicode;
                byte[] unicodeBytes = unicode.GetBytes("This is  a test from server <EOF>");
                byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
                message.Data = asciiBytes;
                TCPRemoteClient remoteClient;
                if(server.GetTCPRemoteClient(1, out remoteClient))
                {
                    remoteClient.Send(message);
                }

                //Thread.Sleep(1000);
                //Console.ReadLine();
                //message = new TCPSendPackage();
                //message.Data = new byte[0];
                //client.Send(message);
            }
            myLogHandler.ShutDown();
        }
Exemplo n.º 3
0
        public static void BuildRegisterMediaConsumerTCPMessage(out TCPSendPackage tcpPackage)
        {
            tcpPackage = new TCPSendPackage();

            tcpPackage.Data = Encoding.ASCII.GetBytes(String.Format("<message type=\"register_media_consumer\"/>"));
        }
Exemplo n.º 4
0
        public static void BuildImageReceiveRequestAckTCPMessage(out TCPSendPackage tcpPackage)
        {
            tcpPackage = new TCPSendPackage();

            tcpPackage.Data = Encoding.ASCII.GetBytes(String.Format("<message type=\"image_receive_request_response_ack\"/>"));
        }
Exemplo n.º 5
0
        public void Send(TCPSendPackage message)
        {
            if (_socket.Connected)
            {
                // Convert the string data to byte data using ASCII encoding.
                byte[] byteData = message.Data;

                StateObject state = new StateObject();
                state.sender = this;
                state.workSocket = _socket;
                // Begin sending the data to the remote device.
                _socket.BeginSend(byteData, 0, byteData.Length, 0,
                    new AsyncCallback(SendCallback), state);
            }
        }
 private void sendRegisterMessage_Click(object sender, RoutedEventArgs e)
 {
     TCPSendPackage package = new TCPSendPackage();
     package.Data = Encoding.ASCII.GetBytes("<message type=\"register_media_producer\"/>");
     _mediaProducer.Send(package);
 }
        private void sendImage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                System.Drawing.Image image = System.Drawing.Image.FromFile("../../sample_jpeg.jpg", false);
                Log.info("Loading image was a sucess.");

                ImageMessage message;
                ImageMessageBuilder.BuildImageMessage(image, 0, out message);

                TCPSendPackage package = new TCPSendPackage();

                package.Data = Encoding.ASCII.GetBytes(message.ImageSendRequest);
                _mediaProducer.Send(package);

            }
            catch (FileNotFoundException ex)
            {
                Log.error("Failed to load image: {0}", ex.Message);
            }
            catch (OutOfMemoryException ex)
            {
                Log.error("Failed to load image: {0}", ex.Message);
            }
        }