1
Answer

C# UDP network stream...

ewomack2000

ewomack2000

19y
6.8k
1
Hello. Trying to write a program using UDP that reads from the network... I'm not using the UDPClient class (I probably should). I'm new to socket programming (and somewhat new to C#); all I need is to read the network stream, but the NetworkStream does not work with connectionless sockets (UDP); anyone know how I can do this? I've been searching the www with no luck so far. Here's my code so far (I X'd out the IP address and port to protect the innocent): using System; using System.Text; using System.Net; using System.Net.Sockets; namespace SocketTest { class Class1 { static void Main(string[] args) { IPAddress ia = IPAddress.Parse("XX.XXX.XXX.XXX"); IPEndPoint ie = new IPEndPoint(ia, XXXX); byte[] msg = Encoding.ASCII.GetBytes("1234stilltestingalot"); Socket ed = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); ed.SendTo(msg,ie); ed.Close(); } } } This program sends a message just fine, but I have to use a packet analyzer to read the server output. I'd like the server output to display in the console. Any help would be appreciated! Thank you!
Answers (1)