WebSocketPort

WebSocketPort

#Overview

name: WebSocketPort

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of WebSocketPort is to define the port number on which the WebSocket server listens for incoming connections in the Unreal Engine’s WebSocket networking system.

This setting variable is primarily used by the WebSocketNetworking plugin, which is an experimental networking module for Unreal Engine. It is specifically utilized within the UWebSocketNetDriver class, which is responsible for managing WebSocket-based network connections.

The value of WebSocketPort is set as a configuration property (UPROPERTY(Config)) within the UWebSocketNetDriver class. This means it can be configured in the project settings or through configuration files.

WebSocketPort interacts with other networking-related variables and objects, such as InternetAddr, LocalURL, and LocalAddr, to establish and manage WebSocket connections.

Developers must be aware of the following when using this variable:

  1. It’s part of an experimental plugin, so it may not be suitable for production use without thorough testing.
  2. The port number should be carefully chosen to avoid conflicts with other services or applications.
  3. Firewall and network configurations may need to be adjusted to allow connections on this port.

Best practices when using this variable include:

  1. Ensure the chosen port is not already in use by other applications or services.
  2. Use a port number above 1024 to avoid conflicts with well-known system ports.
  3. Configure the WebSocketPort in a way that’s easily modifiable for different environments (development, testing, production).
  4. Consider security implications and use appropriate encryption and authentication mechanisms when using WebSocket connections.
  5. Test the WebSocket functionality thoroughly across different network conditions and environments.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Plugins/Experimental/WebSocketNetworking/Config/BaseWebSocketNetDriver.ini:22, section: [/Script/WebSocketNetworking.WebSocketNetDriver]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Experimental/WebSocketNetworking/Source/WebSocketNetworking/Private/WebSocketNetDriver.cpp:61

Scope (from outer to inner):

file
function     bool UWebSocketNetDriver::InitConnect

Source code excerpt:

	bool Ok;
	InternetAddr->SetIp(*ConnectURL.Host, Ok);
	InternetAddr->SetPort(WebSocketPort);

	FWebSocket* WebSocket = new FWebSocket(*InternetAddr);
	UWebSocketConnection* Connection = (UWebSocketConnection*)ServerConnection;
	Connection->SetWebSocket(WebSocket);

	FWebSocketPacketReceivedCallBack CallBack;

#Loc: <Workspace>/Engine/Plugins/Experimental/WebSocketNetworking/Source/WebSocketNetworking/Private/WebSocketNetDriver.cpp:97

Scope (from outer to inner):

file
function     bool UWebSocketNetDriver::InitListen

Source code excerpt:

	CallBack.BindUObject(this, &UWebSocketNetDriver::OnWebSocketClientConnected);

	if(!WebSocketServer->Init(WebSocketPort, CallBack))
		return false;

	WebSocketServer->Tick();
	LocalURL.Port = WebSocketPort;
	LocalAddr = GetSocketSubsystem()->GetLocalBindAddr(*GLog);
	LocalAddr->SetPort(WebSocketPort);
	UE_LOG(LogWebSocketNetworking, Log, TEXT("%s WebSocketNetDriver listening on port %i"), *GetDescription(), LocalURL.Port);

	// server has no server connection.
	ServerConnection = NULL;
	return true;
}

#Loc: <Workspace>/Engine/Plugins/Experimental/WebSocketNetworking/Source/WebSocketNetworking/Public/WebSocketNetDriver.h:19

Scope (from outer to inner):

file
class        class UWebSocketNetDriver : public UNetDriver

Source code excerpt:

	/** WebSocket server port*/
	UPROPERTY(Config)
	int32 WebSocketPort;

	//~ Begin UNetDriver Interface.
	virtual bool IsAvailable() const override;
	virtual bool InitBase(bool bInitAsClient, FNetworkNotify* InNotify, const FURL& URL, bool bReuseAddressAndPort, FString& Error) override;
	virtual bool InitConnect(FNetworkNotify* InNotify, const FURL& ConnectURL, FString& Error) override;
	virtual bool InitListen(FNetworkNotify* InNotify, FURL& LocalURL, bool bReuseAddressAndPort, FString& Error) override;