I want to use UDP to let Unreal receive message from Java, but the messages sent from Java are not received by Unreal.
In the beginPlay method of the player:
ScreenMsg(“RECEIVER INIT”);
int32 BufferSize = 2 * 1024 * 1024;
ListenSocket = FUdpSocketBuilder(TEXT("MySocket"))
.AsNonBlocking()
.AsReusable()
.BoundToAddress(FIPv4Address::Any)
.BoundToPort(1324)
.WithReceiveBufferSize(BufferSize);
FTimespan ThreadWaitTime = FTimespan::FromMilliseconds(100);
UDPReceiver = new FUdpSocketReceiver(ListenSocket, ThreadWaitTime, TEXT("UDP RECEIVER"));
UDPReceiver->OnDataReceived().BindUObject(this, &AMyProject2Character::Recv);
The Recv method is very, very simple:
ScreenMsg("Receiving Data...");
But “Receiving Data…” is never printed on the screen. Anyone an idea?
P.S. Probably irrelevant for the question, but may come in handy for people Googling this topic, the Java code I use for sending messages is:
public static void main(String args[]) throws Exception {
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("127.0.0.1");
byte[] sendData;
String sentence = "foo";
sendData = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 1324);
while (true) {
clientSocket.send(sendPacket);
Thread.sleep(100);
}
}