- Home /
UDP Packet and EC2
I dont receive any UDP packet on server hosted on EC2 from some devices
These devices dont receive any packets from server as well.
Devices that do receive the packets work perfectly as intended.
TCP works just fine on them..
I am using same port for both TCP and UDP (tried using different)
I read it could be a problem of NAT but couldnt find anything about solving it..
Anyone facing same issue?
EDIT: I can see the outgoing packet from client -> server on Wireshark but server doesnt receive it.
Im using Socket class I tried TCPListener TCPCLient and UDPClient..
Server side
void ListenTCP()
{
TCPSocket = new TcpListener(IPAddress.Any, Port);
TCPSocket.Start();
while (true)
{
TcpClient client;
try
{
client = TCPSocket.AcceptTcpClient();
}
catch (Exception) { break; }
try
{
TCPHandler.HandleTCPClient(client);
}
catch (Exception e) { Debug.Log(e); }
}
}
void ListenUDP()
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
s.Bind(new IPEndPoint(IPAddress.Any, Port));
UDPHandler.SetClient(s);
//UdpClient c = new UdpClient(Port);
//UDPHandler.SetClient(c);
EndPoint ep = new IPEndPoint(IPAddress.Any, 0);
byte[] buf = new byte[MaxPacketSize];
while (true)
{
try
{
s.ReceiveFrom(buf, ref ep);
//buf = c.Receive(ref ep);
}
catch (Exception e) { Debug.Log(e); break; }
try
{
UDPHandler.HandleUDPPacket(buf, ep);
}
catch (Exception e) { Debug.Log(e); }
}
}
Client Side
public void ConnectToServer(Action connected)
{
new Thread(() =>
{
while (true)
{
try
{
TCPSocket = new TcpClient();
TCPSocket.Connect(Host, Port);
UDPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
UDPSocket.Bind(new IPEndPoint(IPAddress.Any, ((IPEndPoint)TCPSocket.Client.LocalEndPoint).Port));
UDPSocket.Connect(Host, Port);
//UDPSocket = new UdpClient(((IPEndPoint)TCPSocket.Client.LocalEndPoint).Port);
//UDPSocket.Connect(Host, Port);
Debug.Log("Connected");
break;
}
catch (Exception e) { Debug.LogError(e); }
}
TCPThread = new Thread(() => { TCPHandler.ListenTCP(TCPSocket); });
TCPThread.Start();
UDPThread = new Thread(() => { UDPHandler.ListenUDP(UDPSocket); });
UDPThread.Start();
Ready = true;
connected?.Invoke();
}).Start();
}
How with code are you trying to achieve to send receive UDP
I've added code above.. I tried using UDP Client.. It was the same..
Have you been trying to use mirror?
Also there is new networking in beta I would recommend trying that as you will be on new releases compatible.
It's specially good to go there while you are on the beginning of multiplayer project.
And for beta you will get fast response of the unity team
I am using EC2, with UDP (and HTTPS for login). I haven't encountered such problems yet, I was even able to host a game on a cell phone (not on wifi) and then nat-punch using EC2 and connect to it from another cell phone. I am using Lidgren library, It's a nice little wrap around UDP that gives you multiple levels of reliability, ordering and congestion control