Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - JosephHK

Pages: [1]
1
TNet 3 Support / Re: Cant recieve UDP Packet from server host on amazon ec2
« on: February 20, 2017, 08:38:27 AM »
Hmm... I can't even remember why I had it converted to bytes there... So you're saying replacing that line makes everything work properly without any additional changes?

P.S. Back when I wrote TNet, Amazon's EC2 didn't support UDP for security reasons. I didn't even realize that it's usable now... TNet in general uses TCP for most things. UDP is only used for packets you need to send frequently with each new one replacing the state of the previous -- such as position updates in a FPS game.
Yes, this replacement make my desktop and android phone able to receive udp packet from ec2.

2
TNet 3 Support / Re: Cant recieve UDP Packet from server host on amazon ec2
« on: February 15, 2017, 10:08:34 PM »
After more careful examination, It seems that it can be solved easily by changing

IPAddress ip = new IPAddress(player.tcpEndPoint.Address.GetAddressBytes());
SetPlayerUdpEndPoint(player, new IPEndPoint(ip, port));

to

SetPlayerUdpEndPoint(player, new IPEndPoint(player.tcpEndPoint.Address, port));

3
TNet 3 Support / Re: Cant recieve UDP Packet from server host on amazon ec2
« on: February 15, 2017, 05:19:13 PM »
Looks like it is a major bug.

I am not familiar socket programming so I did an experiment.

I write a simple udp server and run it on amazon ec2, then I connect it using a simple udp client.

Server
  1. static void Main (string[] args) {
  2.         int port = 5100;
  3.         Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  4.         socket.Bind(new IPEndPoint(IPAddress.Any, port));
  5.  
  6.         EndPoint bufferEndPoint = new IPEndPoint(IPAddress.Any, 0);
  7.  
  8.         byte[] receiveBuffer = new byte[1024];
  9.         socket.BeginReceiveFrom(receiveBuffer, 0, receiveBuffer.Length, SocketFlags.None, ref bufferEndPoint, OnReceived, socket);
  10.  
  11.         while (true);
  12. }
  13.  
  14. private static void OnReceived (IAsyncResult ar) {
  15.         int bytesReceived;
  16.         EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
  17.  
  18.         Socket socket = ar.AsyncState as Socket;
  19.  
  20.         bytesReceived = socket.EndReceiveFrom(ar, ref remoteEndPoint);
  21.  
  22.         Console.WriteLine(remoteEndPoint + ":" + bytesReceived);
  23.  
  24.         socket.SendTo(new byte[] { 1, 2, 3, 4, 5, 6, 7 }, remoteEndPoint);
  25. }

Client
  1. void Start () {
  2.         Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  3.         socket.Bind(new IPEndPoint(IPAddress.Any, 0));
  4.  
  5.         socket.Connect(new IPEndPoint(IPAddress.Parse("52.78.177.7"), 5100));
  6.         EndPoint bufferEndPoint = new IPEndPoint(IPAddress.Any, 0);
  7.  
  8.         byte[] receiveBuffer = new byte[1024];
  9.         socket.BeginReceiveFrom(receiveBuffer, 0, receiveBuffer.Length, SocketFlags.None, ref bufferEndPoint, OnReceived, socket);
  10.  
  11.         socket.Send(new byte[] {1,2,3,4 });
  12. }
  13.  
  14. private static void OnReceived (IAsyncResult ar) {
  15.         int bytesReceived;
  16.         EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
  17.         Socket socket = ar.AsyncState as Socket;
  18.         bytesReceived = socket.EndReceiveFrom(ar, ref remoteEndPoint);
  19.  
  20.         Debug.Log(bytesReceived);
  21. }

And it works. The server and client can both receive udp message from each other.

Finally, I figured out why tnet udp protocol not works for at least me.

tnet's code
  1.                                         case Packet.RequestSetUDP: {
  2.                                                 int port = reader.ReadUInt16();
  3.                                                 if (port != 0 && mUdp.isActive && player.tcpEndPoint != null) {
  4.                                                         IPAddress ip = new IPAddress(player.tcpEndPoint.Address.GetAddressBytes());
  5.                                                         SetPlayerUdpEndPoint(player, new IPEndPoint(ip, port));
  6.                                                 } else
  7.                                                         SetPlayerUdpEndPoint(player, null);
  8.                                                        
  9.                                                 // Let the player know if we are hosting an active UDP connection
  10.                                                 ushort udp = mUdp.isActive ? (ushort)mUdp.listeningPort : (ushort)0;
  11.                                                 player.BeginSend(Packet.ResponseSetUDP).Write(udp);
  12.                                                 player.EndSend();
  13.  
  14.                                                 // Send an empty packet to the target player to open up UDP for communication
  15.                                                 if (player.udpEndPoint != null) {
  16.                                                         mUdp.SendEmptyPacket(player.udpEndPoint);
  17.                                                 }
  18.                                                 break;
  19.                                         }
  20.  

I used the remote client's IPEndPoint created internally when the udp message is received, and tnet create the IPEndPoint using IPAddress and port sent via tcp.

I roughly modified tnet's code and send RequestSetUDP packet via udp and it seems to work without using upnp.OpenUDP(udpPort).

Please confirm it and make a official fix if it is correct

4
TNet 3 Support / Re: Cant recieve UDP Packet from server host on amazon ec2
« on: February 14, 2017, 08:16:36 AM »
Unfortunately, it only works on my desktop but not on my android mobile phone. So I still need help :'(

5
TNet 3 Support / Re: Cant recieve UDP Packet from server host on amazon ec2
« on: February 14, 2017, 07:55:05 AM »
It seems that I have solved it.

I used UPnP.OpenUDP before calling TNManager.StartUDP and now the client can receive udp packet from the server

UPnP upnp = new UPnP();
int udpPort = Random.Range(10000, 50000);
upnp.OpenUDP(udpPort);
TNManager.StartUDP(udpPort);

6
TNet 3 Support / Re: Cant recieve UDP Packet from server host on amazon ec2
« on: February 13, 2017, 03:08:09 PM »
I also checked that the ResponseSetUDP Packet can be received but the empty udp packet cannot be received :-\

7
TNet 3 Support / Cant recieve UDP Packet from server host on amazon ec2
« on: February 13, 2017, 02:55:24 PM »
The tcp and udp ports are both opened and I also checked TNManager.canUseUDP which returns true.

I modified the GameClient class to check whether I can recieve Udp packet:
while (keepGoing && isActive && mUdp.ReceivePacket(out buffer, out ip)) {
   Debug.Log("Received Udp Packet");
   mUdpIsUsable = true;
   keepGoing = ProcessPacket(buffer, ip);
   buffer.Recycle();
}

However, even in the Frequent Packets demo, "Received Udp Packet" is never logged when I connected to the server hosted on amazon ec2.
Instead, the received packet sent via SendQuickly is tcp.

(The udp packets can be received when the sever is hosted locally.)

Any suggestion please?

8
Can you modify the TNSerailizer so that it is possible to register the type by method like TNSerailizer.RegisterBinarySerializer(Type type, byte id)?

9
Oh. I knew the reason now.

The types of the arguments of a RFC message are serialized as strings. And the type of the struct implementing the IBinarySerializable interface cost 50 bytes.

It is really inefficient.
May I require an corresponding improvement please?

10
So what is packet payload for a RFC message with a IBinarySerializable as the only argument when nothing is written into the BinaryWriter passed to the IBinarySerializable?

I did a simple test. If I am correct, it seems that an empty IBinarySerializable argument will cost unacceptable 50 bytes. Please clarify.

Pages: [1]