Skip to main content
Version: 2.x

UOdinSocket

An opaque type representing an ODIN socket

Declaration
UCLASS(ClassGroup = Odin, Blueprintable, BlueprintType)
class ODIN_API UOdinSocket : public UObject
  • Header: #include "OdinSocket.h"
  • Module: Odin
  • Inherits from: UObject
  • Blueprint: Blueprint type, Blueprintable · Blueprint reference
note

Sockets are bound to the current room session: they do not survive a reconnect, and sockets to a specific peer are closed automatically when that peer leaves the room.

Overview​

Functions​

NameDescription
ConstructSocketCreates an empty socket object.
ResetSocketCloses the specified ODIN socket handle, therefore local socket can not send
ResetOdinSocketByHandleResets the specified ODIN socket handle
CreateOpens the socket in a room.
GetRemotePeerIdReturns the peer on the other end of the socket, or 0 for a socket to all peers.
GetSocketLabelReturns the label the socket was created with.
GetSocketNamedLabelReturns the label the socket was created with, as a Name.
GetSocketInfoReturns information about the socket: room, kind, direction, remote peer, label, priority and the number of unsent bytes.
SendSends a byte array to the peer (or peers) on the other end of the socket.
SendStringSends a string, encoded as UTF-8, to the peer (or peers) on the other end of the socket.
IsReadyChecks socket and socket info.
GetNativeHandle
GetHandle
InvalidateHandleDrops the reference to the native socket without touching it (e.g.
SetHandle

Functions​

ConstructSocket​

Overload 1

Static · Blueprint: Construct Socket

Creates an empty socket object. Call Create Socket on it to open the socket in a room, or use Open Socket on the room, which does both.

UFUNCTION(BlueprintCallable, Category = "Odin")
static UOdinSocket* ConstructSocket(UObject* WorldContextObject);
ParameterTypeDescription
WorldContextObjectUObject*

Returns UOdinSocket*

Overload 2

Static

static UOdinSocket* ConstructSocket(UObject* WorldContextObject, OdinSocket* handle);
ParameterTypeDescription
WorldContextObjectUObject*
handleOdinSocket*

Returns UOdinSocket*

ResetSocket​

Blueprint: Reset Socket

Closes the specified ODIN socket handle, therefore local socket can not send

UFUNCTION(BlueprintCallable, Category = "Odin")
bool ResetSocket();

Returns bool

ResetOdinSocketByHandle​

Static

Resets the specified ODIN socket handle

static bool ResetOdinSocketByHandle(OdinSocket* socket);
ParameterTypeDescription
socketOdinSocket*

Returns bool

Create​

Blueprint: Create Socket

Opens the socket in a room.

UFUNCTION(BlueprintCallable, Category = "Odin")
UOdinSocket* Create(
UOdinRoom* Room,
EOdinSocketKind SocketKind,
int64 TargetPeerId,
int32 Label,
int32 Priority);
ParameterTypeDescription
RoomUOdinRoom*The room to open the socket in.
SocketKindEOdinSocketKindReliable or unreliable delivery.
TargetPeerIdint64The receiving peer, or 0 for all peers in the room.
Labelint32An arbitrary number the receivers can read with Get Label, e.g. to tell several sockets apart.
Priorityint32Transport priority; 0 is the default, higher values are sent first. High values can impact voice quality.

Returns UOdinSocket* – The socket itself. Check Is Ready before sending.

GetRemotePeerId​

Blueprint: Get Remote Peer Id

Returns the peer on the other end of the socket, or 0 for a socket to all peers.

UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Odin|Socket|Info")
int64 GetRemotePeerId();

Returns int64

GetSocketLabel​

Blueprint: Get Label

Returns the label the socket was created with.

UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Odin|Socket|Info")
int32 GetSocketLabel();

Returns int32

GetSocketNamedLabel​

Blueprint: Get Named Label

Returns the label the socket was created with, as a Name.

UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Odin|Socket|Info")
FName GetSocketNamedLabel();

Returns FName

GetSocketInfo​

Blueprint: Get Socket Info

Returns information about the socket: room, kind, direction, remote peer, label, priority and the number of unsent bytes.

UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Odin|Socket|Info")
FOdinSocketInfo GetSocketInfo();

Returns FOdinSocketInfo

Send​

Blueprint: Send

Sends a byte array to the peer (or peers) on the other end of the socket.

UFUNCTION(BlueprintCallable, Category = "Odin|Socket")
bool Send(TArray<uint8> Message);
ParameterTypeDescription
MessageTArray<uint8>byte array

Returns bool – true on ODIN_ERROR_SUCCESS or false

SendString​

Blueprint: Send String

Sends a string, encoded as UTF-8, to the peer (or peers) on the other end of the socket.

UFUNCTION(BlueprintCallable, Category = "Odin|Socket")
bool SendString(const FString& Message);
ParameterTypeDescription
Messageconst FString&String Message

Returns bool – true on ODIN_ERROR_SUCCESS or false

IsReady​

Const · Blueprint: Is Ready

Checks socket and socket info. (extra socket info call)

UFUNCTION(BlueprintPure, Category = "Odin|Socket")
bool IsReady() const;

Returns bool – true if this appears to be a valid object and unsent bytes are 0

GetNativeHandle​

Const · Inline

OdinSocket* GetNativeHandle() const;

Returns OdinSocket*

GetHandle​

Const · Inline

TWeakObjectPtr<UOdinHandle> GetHandle() const;

Returns TWeakObjectPtr<UOdinHandle>

InvalidateHandle​

Inline

Drops the reference to the native socket without touching it (e.g. after the owning room was freed).

void InvalidateHandle();

SetHandle​

Inline

void SetHandle(OdinSocket* handle);
ParameterTypeDescription
handleOdinSocket*

Events​

OnSocketMessageReceivedBP​

Blueprint: On Socket Message Received

Raised when a message arrives on this socket.

UPROPERTY(BlueprintAssignable, Category = "Odin|Socket|Events")
FOdinSocketReceivedDelegate OnSocketMessageReceivedBP;

Signature: FOdinSocketReceivedDelegate void(UOdinRoom* room, UOdinSocket* socket, const TArray<uint8>& data) (multicast)