Exemplo n.º 1
0
        /// <summary>
        /// Sends an offer message via UDP
        /// </summary>
        /// <param name="rMsg">the RequestMessage object to be sent</param>
        public void SendOffer(RequestMessage rMsg)
        {
            OfferMessage oMsg    = new OfferMessage(_programName, rMsg.RandNumber, _localIp, ListeningPort);
            var          message = oMsg.ToByteArray();

            try
            {
                _meAsClientUdpServer.Send(message, message.Length, ep);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// send a UDP request message
 /// </summary>
 private void SendRequestMessage()
 {
     if (rx == Mode.Off)
     {
         byte[] responseForRequestMessage;
         int    randNumber = GenerateRandom();
         _myUDPClient.SendRequestMessage(randNumber);
         if (_myUDPClient.ListenToOffers(out responseForRequestMessage))
         {
             if (OfferMessage.TryParseOfferMessage(responseForRequestMessage, _programName, randNumber))
             {
                 OfferMessage oMsg = new OfferMessage(responseForRequestMessage);
                 _logger.PrintLog(String.Format("Got offer message: {0}", oMsg));
                 if (_myTcpClient.TryConnectToServer(oMsg.ServerIPAddress, oMsg.ServerListeningPort))
                 {
                     tx                     = Mode.On;
                     statusChanged          = true;
                     _myClientTCPServerName = oMsg.ServerName;
                 }
             }
         }
     }
 }