Udp. How to recieve.
-
I have just started this. and i m trying to make a chat application that runs over LAN. there might be many other ways and they might be better then using Udp port but i want to understand this thing. i have read some articles before posting but i m now having problem on receiveing messages.
public void waitData() { while(true) { IPEndPoint from = new IPEndPoint(IPAddress.Any,170); string result = ""; Byte[] drec = receive.Receive(ref from); result = Encoding.ASCII.GetString(drec); textBox1.Text = result.ToString(); } }
this code is to recieve messages and i made a thread so it keep waiting for any message to recieve. and i m broadcasting message to network. i m new to this so plz help me :sigh: i think its enough to explain what i want to do but if still you think i had to tell more. tell me. -
I have just started this. and i m trying to make a chat application that runs over LAN. there might be many other ways and they might be better then using Udp port but i want to understand this thing. i have read some articles before posting but i m now having problem on receiveing messages.
public void waitData() { while(true) { IPEndPoint from = new IPEndPoint(IPAddress.Any,170); string result = ""; Byte[] drec = receive.Receive(ref from); result = Encoding.ASCII.GetString(drec); textBox1.Text = result.ToString(); } }
this code is to recieve messages and i made a thread so it keep waiting for any message to recieve. and i m broadcasting message to network. i m new to this so plz help me :sigh: i think its enough to explain what i want to do but if still you think i had to tell more. tell me.So what's the problem? Also, don't keep reinstantiating your
IPEndPoint
in yourwhile
loop. You only need to do this once per end point required for your application. If you're having trouble using UDP classes in .NET then be sure to read about them in the .NET Framework SDK, like the UdpClient[^] class. Many of these include examples and reading about what the methods and properties actually do is important. The documentation I've linked in particular shows you how to send and receive buffers using theUdpClient
. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]