954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# udp client

hi i need to write a program that connects to a device through Ethernet over the UDP protocal and get the data sent by the device. I tried using the .NET udp client methods but was unsuccessful. Can you guys help...this is my code....

static void Main(string[] args)
        {
             byte[] data = new byte[1024];
             IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("192.168.10.2"), 10001);

      Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Dgram, ProtocolType.Udp);
      data = Encoding.ASCII.GetBytes("");
      server.SendTo(data, data.Length, SocketFlags.None, ipep);
      IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
      EndPoint tmpRemote = (EndPoint)sender;

      while(true)
      {
          data = new byte[1024];
          int recv = server.ReceiveFrom(data, ref tmpRemote);

          Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
          Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
         
          file.Close();
      }

Can any of you tell me whats wrong here....the ip address i have given is the ip of the device

dsit86
Newbie Poster
3 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: