Why does UE4 always miss the first packet?

Hi,

I press a button, and it sends a packet, containing a string data “Hello” to my server.

My C# server receives it, and then sends it back to the client (UE4).

My UE4 doesn’t get the packet.

		TArray<uint8> ReceivedData;

		uint32 Size;
		while (mySocket->HasPendingData(Size))
		{
			ReceivedData.SetNumUninitialized(FMath::Min(Size, 65507u));

			int32 Read = 0;
			mySocket->Recv(ReceivedData.GetData(), ReceivedData.Num(), Read);

		}

		if (ReceivedData.Num() <= 0)
		{
			FString temp = TEXT("False");
			return temp;

		}

I press the button the second time,

Server gets it, and now client gets it. And so on.

Why does the client miss the first one?

It’s bad, because if my players type in the correct password and username the first time, the server will say that’s right, but the client will not receive, until the player presses the button the second time.

Thank you.

Hi!
How exactly do you invoke this code? I think problem in that you don’t wait when data come from server, so I mean following:

  1. When you press button in first time you send date on the server and invoke the code for receiving. But server may be ( if we take into account ping) not catch you message and not done responce, when you try receive one.
  2. while (mySocket->HasPendingData(Size)) this code only check that the socket has any pending data on the queue and how I think the socket hasn’t pending data yet.
  3. When you press button again socket already have data and you handled them successfully.

So I advice for you try check socket several times in timer. But it not so good solution if you would like use socket many times. It this way I suggest use more general solution like this: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

P.S. Hi from broly… :wink:

Yo, Yogi bear.

So from Ramas link, I set a timer, that listens for packets.

Funny thing is, it works when I host server on PC, and client on Same PC.

If I play from different IP I miss packets. It’s TCP!