Aaditya Bhardwaj

Aaditya Bhardwaj

  • 1.6k
  • 57
  • 325

I want to receive data from a gps device and want to show t

Apr 28 2019 7:13 AM
my code is :
void ReceivedByServer()
{
   Socket socketReceive = new Socket(AddressFamily.InterNetwork, SocketType.Stream,    ProtocolType.Tcp);
   int portReceive = 90;
   IPEndPoint iPEndPointReceive = new IPEndPoint(IPAddress.Parse("0.0.0.0"),    portReceive);
   socketReceive.Bind(iPEndPointReceive);
   socketReceive.Listen(10);
   ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12;
   while (true)
   {
      Socket temp = null;
      try
      {
         temp = socketReceive.Accept();
         byte[] messageReceivedByServer = new byte[1000];
         int sizeOfReceivedMessage = temp.Receive(messageReceivedByServer, 0,          messageReceivedByServer.Length, SocketFlags.None);
         string str = Encoding.UTF8.GetString(messageReceivedByServer);
         labelShow.Text += "\r\nClient: " + str;
      }
      catch (Exception ex)
      {
         MessageBox.Show(ex.Message + "\n" + ex.StackTrace + "\n" + ex.HelpLink + "\n" +          ex.InnerException
         + "\n" + ex.Source + "\n" + ex.TargetSite);
      }
   }
}
 


I am getting response from gps device but the message is not shown in string format
i got the output like 

Answers (1)