How To Receive Data From UDP Client?

  • Thread starter Thread starter Yexx
  • Start date Start date
Y

Yexx

Guest
Hello everyone,

I am working on a simple multiplayer game. I wrote a C++ server and I'm now trying to write the client in C# in the Unity game engine. I'm pretty new to networking. I'm a bit confuse on how this works in C#. I've got this so far, but it doesn't seem to work and throws an error:



IPEndPoint ep = new IPEndPoint(IPAddress.Parse(serverIPAddress), port);


UdpClient udp = new UdpClient();
byte[] data = udp.Receive(ref ep);
string s = Encoding.ASCII.GetString(data, 0, data.Length);

print(s);


The error:

SocketException: An invalid argument was supplied.

System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint& remoteEP) (at <735c83e43c004ee998f77c68cf8035da>:0)
System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint& remoteEP) (at <735c83e43c004ee998f77c68cf8035da>:0)
System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) (at <735c83e43c004ee998f77c68cf8035da>:0)
client.Update () (at Assets/client.cs:35)

Thanks in advance!

Continue reading...
 

Similar threads

P
Replies
0
Views
176
Policy standard local admin account with Active Di
P
J
Replies
0
Views
63
Jessi_ca
J
Back
Top