emscripten-core / emscripten-core/emscripten
Emscripten and Unreal Engine 4 Socket Issue
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
**Preface**
I'm working with Unreal Engine 4 (UE4) compiled from source. I'm creating an HTML5 game that is multiplayer. UE4 is mostly written in C++ and uses combination of emscripten, python, etc to package for HTML5 deployment.
**Problem**
The game will **not** connect to my remote dedicated game server when I load the game from my external Azure site (https://testwinvm.eastus.cloudapp.azure.com/VirtualShow.html). Example of this Scenario's architecture below:

When I load the game from local (http://localhost:8000), the game connects perfectly fine to my remote dedicated game server. Example of this Scenario's architecture below:

I've been inspecting the Debug Console between both scenarios. I thought this might be an CORS issue, but I do **not** notice any difference in the Headers being sent between the two scenarios. I thought maybe the MIME type encodings are incorrect between the two scenarios, but they look exactly the same. Example below, left is local/scenario two and right is remote/scenario one:

The only thing I notice in the Debug Console that is different between the two scenarios is after the game is already fully loaded in browser. When I execute the connection command, the console logs varying outputs.
**Scenario One Output**

**Scenario Two Output**

According to those logs at some point during the socket connection initialization there is an error and the error varies between the two scenarios. I believe Error Code 26 means "Connection already in progress" and is an **okay** error. Error Code 23 is **not** good because I think it means "Unreachable Host". I don't understand how the host could be unreachable or why initiating the socket connection is different. Below is the C++ code that is generating these logs.
FWebSocket::FWebSocket(
const FInternetAddr& ServerAddress
)
:IsServerSide(false)
{
SockFd = socket(AF_INET, SOCK_STREAM, 6);
if (SockFd == -1)
{
UE_LOG(LogWebSocketNetworking, Error, TEXT("Socket creation failed "));
}
else
{
UE_LOG(LogWebSocketNetworking, Warning, TEXT(" Socked %d created "), SockFd);
}
fcntl(SockFd, F_SETFL, O_NONBLOCK);
memset(&RemoteAddr, 0, sizeof(RemoteAddr));
RemoteAddr.sin_family = AF_INET;
RemoteAddr.sin_port = htons(ServerAddress.GetPort());
int Ret = connect(SockFd, (struct sockaddr *)&RemoteAddr, sizeof(RemoteAddr));
UE_LOG(LogWebSocketNetworking, Warning, TEXT(" Connect socket returned %d to %s. Error Code: %d"), Ret, *ServerAddress.ToString(false), ((Ret != 0) ? errno : 0));
}
I modified this snippet a bit so that the UE4 references were more in context, [but the full unmodified file is here][1]. [If you wish to see the full UE4 socket implementation it's here][2]. I'm still pretty new with C++, so nothing with that above code seems wrong too me. I've been digging through [Oracle documentation][3] on Sockets, but nothing I've tried has helped with this problem. Does anybody have any ideas?
**Additional Notes**
The project is hosted here: https://testwinvm.eastus.cloudapp.azure.com/VirtualShow.html
Project download to run locally is here: https://testwinvm.eastus.cloudapp.azure.com/VirtualShow.zip
The dedicated game server IP for terminal's **open** command: 20.55.123.171
WebAssembly doesn't compile while Firefox debugger is open, so make sure you open the console after the game is fully loaded.
**TL;DR** It's like Firefox is blocking my Socket Connection when it's opening the site on a remote server... But it's totally cool with Socket Connections if the site is being opened on localhost. **I do not know why.** Can you help?
[1]: https://github.com/UnrealEngineHTML5/UnrealEngine/blob/4.24-html5/Engine/Plugins/Experimental/WebSocketNetworking/Source/WebSocketNetworking/Private/WebSocket.cpp
[2]: https://github.com/UnrealEngineHTML5/UnrealEngine/tree/4.24-html5/Engine/Plugins/Experimental/WebSocketNetworking/Source/WebSocketNetworking
[3]: https://docs.oracle.com/cd/E19620-01/805-4041/6j3r8iu2l/index.html
Contributor guide
Assessment
This issue has not been assessed yet.