Currently I’m trying to export a simple topdown template to html5 with a custom written c++ class using FSocket to enable blueprinting tcp sockets for UE4 designers in our company. We have a node.js backend that accepts both TCP and Websocket connections on different ports.
When I run the current game in editor (or export for mac osx), a TCP connection is made and data send and receive has no problems.
However after exporting to HTML5, the websocket connection is made, yet the FSocket->Connect() always return false. There are no logs or errors about the condition of the connection on browser console log, but I can see a successful connection made on the server part.
This is the header that UE4 is sending when game is run in HTML5.
<< IN: 127.0.0.1|56135
GET / HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: 127.0.0.1:8000
Origin: http://127.0.0.1:55966
Sec-WebSocket-Protocol: binary
Pragma: no-cache
Cache-Control: no-cache
Sec-WebSocket-Key: MKHvPf1T2PK1Y/j1RaRzxw==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: x-webkit-deflate-frame
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12
Here is the code I’m using to connect to the current backend.
UTCPSocketNetworking *UTCPSocketNetworking::TCPConnect ()
{
// Do not try to connect again
if ( this->IsConnected ) {
printGreen("TCPConnect -- Already connected");
OnSocketConnected.Broadcast();
return this;
}
//<editor-fold desc="Check missing variables">
{
// Not connected yet
IsConnected = false;
if ( ServerIP == "" ) {
printRed("TCPConnect -- ERROR -- Server ip or name is not set yet");
OnSocketCouldNotConnect.Broadcast();
return this;
}
if ( !ServerPort ) {
printRed("TCPConnect -- ERROR -- Server port is not set yet");
OnSocketCouldNotConnect.Broadcast();
return this;
}
if ( SocketName == "" ) {
printRed("TCPConnect -- ERROR -- Socket name is not set yet");
OnSocketCouldNotConnect.Broadcast();
return this;
}
}
//</editor-fold>
//<editor-fold desc="Create socket">
{
FIPv4Address ip;
FIPv4Address::Parse(ServerIP, ip);
auto LocalAddress = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
LocalAddress->SetIp(ip.GetValue());
LocalAddress->SetPort(ServerPort);
Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, this->SocketName, false);
if ( !Socket->Connect(*LocalAddress) ) {
printRed("TCPConnect -- ERROR -- Could not connect to local address");
OnSocketCouldNotConnect.Broadcast();
return this;
}
}
//</editor-fold>
IsConnected = true;
OnSocketConnected.Broadcast();
return this;
}
- This method is called from a blueprint.
- Socket is an FSocket.
- ServerIP, ServerPort and SocketName are variables visible for blueprinting.
- IsConnected is a private variable for checking if socket is connected on c++ side.
- OnSocketCouldNotConnect and OnSocketConnected are delegates declared via DECLARE_DYNAMIC_MULTICAST_DELEGATE and are working in each case.
- Experimental HTML5Networking is enabled in Unreal Engine plugins.
- Tried to run the game in Google, Firefox and Safari, all resulting with the same fail.
Is there any other way of using the FSocket to enable HTML5 networking / websockets ? Are there any tutorials/codes that I can look at for understanding the concept as the documentation does not exist.