emscripten-core / emscripten-core/emscripten

Emscripten and Unreal Engine 4 Socket Issue

Open
#14,208 0 comments 0 reactions 0 assignees View on GitHub
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:

![Image of Scenario 1](https://answers.unrealengine.com/storage/temp/338716-scenario-1.png)

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:

![Image of Scenario 2](https://answers.unrealengine.com/storage/temp/338717-scenario-2.png)

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:

![Image of Headers and MIME Types](https://answers.unrealengine.com/storage/temp/338718-headers.png)

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**

![Image of Remote Console Output](https://answers.unrealengine.com/storage/temp/338719-remote-logs.png)

**Scenario Two Output**

![Image of Local Console Output](https://answers.unrealengine.com/storage/temp/338720-local-logs.png)

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.