Table of Contents

Class ISteamNetworkingSockets

Namespace
MarymoorStudios.Core.Steamworks
Assembly
MarymoorStudios.Core.Steamworks.dll
public sealed class ISteamNetworkingSockets : SteamNativeObject
Inheritance
ISteamNetworkingSockets
Inherited Members

Fields

INTERFACE_VERSION

public const string INTERFACE_VERSION = "SteamNetworkingSockets012"

Field Value

string

Methods

AcceptConnection(HSteamNetConnection)

public EResult AcceptConnection(HSteamNetConnection conn)

Parameters

conn HSteamNetConnection

Returns

EResult

BeginAsyncRequestFakeIP(int)

public bool BeginAsyncRequestFakeIP(int numPorts)

Parameters

numPorts int

Returns

bool

CloseConnection(HSteamNetConnection, int, string?, bool)

public bool CloseConnection(HSteamNetConnection peer, int reason = 0, string? pszDebug = null, bool enableLinger = false)

Parameters

peer HSteamNetConnection
reason int
pszDebug string
enableLinger bool

Returns

bool

CloseListenSocket(HSteamListenSocket)

public bool CloseListenSocket(HSteamListenSocket socket)

Parameters

socket HSteamListenSocket

Returns

bool

ConfigureConnectionLanes(HSteamNetConnection, ReadOnlySpan<int>, ReadOnlySpan<ushort>)

public EResult ConfigureConnectionLanes(HSteamNetConnection conn, ReadOnlySpan<int> lanePriorities, ReadOnlySpan<ushort> laneWeights)

Parameters

conn HSteamNetConnection
lanePriorities ReadOnlySpan<int>
laneWeights ReadOnlySpan<ushort>

Returns

EResult

ConnectByIPAddress(in SteamNetworkingIPAddr, ReadOnlySpan<SteamNetworkingConfigValue>)

public HSteamNetConnection ConnectByIPAddress(in SteamNetworkingIPAddr address, ReadOnlySpan<SteamNetworkingConfigValue> options)

Parameters

address SteamNetworkingIPAddr
options ReadOnlySpan<SteamNetworkingConfigValue>

Returns

HSteamNetConnection

ConnectP2P(in SteamNetworkingIdentity, int, ReadOnlySpan<SteamNetworkingConfigValue>)

Connecting to a peer by id (instead of IP address).

public HSteamNetConnection ConnectP2P(in SteamNetworkingIdentity identityRemote, int remoteVirtualPort, ReadOnlySpan<SteamNetworkingConfigValue> options)

Parameters

identityRemote SteamNetworkingIdentity

The identity of the peer to connect to.

remoteVirtualPort int

The port to connect on (usually 0).

options ReadOnlySpan<SteamNetworkingConfigValue>

Connection options.

Returns

HSteamNetConnection

The connection handle if successful, otherwise Invalid.

Remarks

Begin connecting to a peer that is identified using a platform-specific identifier. This uses the default rendezvous service, which depends on the platform and library configuration. (E.g. on Steam, it goes through the steam backend.) The traffic is relayed over the Steam Datagram Relay network. If you use this, you probably want to call InitRelayNetworkAccess() when your app initializes. If you need to set any initial config options, pass them here. See SteamNetworkingConfigValue for more about why this is preferable to setting the options "immediately" after creation.

ConnectP2PCustomSignaling(ref ISteamNetworkingConnectionSignaling, in SteamNetworkingIdentity, int, ReadOnlySpan<SteamNetworkingConfigValue>)

public HSteamNetConnection ConnectP2PCustomSignaling(ref ISteamNetworkingConnectionSignaling signaling, in SteamNetworkingIdentity peerIdentity, int remoteVirtualPort, ReadOnlySpan<SteamNetworkingConfigValue> options)

Parameters

signaling ISteamNetworkingConnectionSignaling
peerIdentity SteamNetworkingIdentity
remoteVirtualPort int
options ReadOnlySpan<SteamNetworkingConfigValue>

Returns

HSteamNetConnection

ConnectToHostedDedicatedServer(in SteamNetworkingIdentity, int, ReadOnlySpan<SteamNetworkingConfigValue>)

public HSteamNetConnection ConnectToHostedDedicatedServer(in SteamNetworkingIdentity identityTarget, int remoteVirtualPort, ReadOnlySpan<SteamNetworkingConfigValue> options)

Parameters

identityTarget SteamNetworkingIdentity
remoteVirtualPort int
options ReadOnlySpan<SteamNetworkingConfigValue>

Returns

HSteamNetConnection

CreateFakeUDPPort(int)

public ISteamNetworkingFakeUDPPort CreateFakeUDPPort(int idxFakeServerPort)

Parameters

idxFakeServerPort int

Returns

ISteamNetworkingFakeUDPPort

CreateHostedDedicatedServerListenSocket(int, ReadOnlySpan<SteamNetworkingConfigValue>)

public HSteamListenSocket CreateHostedDedicatedServerListenSocket(int localVirtualPort, ReadOnlySpan<SteamNetworkingConfigValue> options)

Parameters

localVirtualPort int
options ReadOnlySpan<SteamNetworkingConfigValue>

Returns

HSteamListenSocket

CreateListenSocketIP(in SteamNetworkingIPAddr, ReadOnlySpan<SteamNetworkingConfigValue>)

public HSteamListenSocket CreateListenSocketIP(in SteamNetworkingIPAddr localAddress, ReadOnlySpan<SteamNetworkingConfigValue> options)

Parameters

localAddress SteamNetworkingIPAddr
options ReadOnlySpan<SteamNetworkingConfigValue>

Returns

HSteamListenSocket

CreateListenSocketP2P(int, ReadOnlySpan<SteamNetworkingConfigValue>)

Listen for connection by CSteamID through the Valve network.

public HSteamListenSocket CreateListenSocketP2P(int localVirtualPort, ReadOnlySpan<SteamNetworkingConfigValue> options)

Parameters

localVirtualPort int

The port to use in ConnectP2P(in SteamNetworkingIdentity, int, ReadOnlySpan<SteamNetworkingConfigValue>) .

options ReadOnlySpan<SteamNetworkingConfigValue>

Socket options.

Returns

HSteamListenSocket

The socket handle if successful, otherwise Invalid.

Remarks

Like CreateListenSocketIP(in SteamNetworkingIPAddr, ReadOnlySpan<SteamNetworkingConfigValue>) , but clients will connect using ConnectP2P(in SteamNetworkingIdentity, int, ReadOnlySpan<SteamNetworkingConfigValue>) . The connection will be relayed through the Valve network.

localVirtualPort specifies how clients can connect to this socket using ConnectP2P(in SteamNetworkingIdentity, int, ReadOnlySpan<SteamNetworkingConfigValue>) . It's very common for applications to only have one listening socket; in that case, use zero. If you need to open multiple listen sockets and have clients be able to connect to one or the other, then localVirtualPort should be a small integer (<1000) unique to each listen socket you create.

If you are listening on a dedicated servers in known data center, then you can listen using this function instead of CreateHostedDedicatedServerListenSocket(int, ReadOnlySpan<SteamNetworkingConfigValue>) , to allow clients to connect without a ticket. Any user that owns the app and is signed in to Steam will be able to attempt to connect to your server. Also, a connection attempt may require the client to be connected to Steam, which is one more moving part that may fail. When tickets are used, then once a ticket is obtained, a client can connect to your server even if they got disconnected from Steam or Steam is offline.

If you use this, you probably want to call InitRelayNetworkAccess() when your app initializes.

If you need to set any initial config options, pass them here. See SteamNetworkingConfigValue for more about why this is preferable to setting the options "immediately" after creation.

CreateListenSocketP2PFakeIP(int, ReadOnlySpan<SteamNetworkingConfigValue>)

public HSteamListenSocket CreateListenSocketP2PFakeIP(int idxFakePort, ReadOnlySpan<SteamNetworkingConfigValue> options)

Parameters

idxFakePort int
options ReadOnlySpan<SteamNetworkingConfigValue>

Returns

HSteamListenSocket

CreatePollGroup()

public HSteamNetPollGroup CreatePollGroup()

Returns

HSteamNetPollGroup

CreateSocketPair(out HSteamNetConnection, out HSteamNetConnection, bool, in SteamNetworkingIdentity, in SteamNetworkingIdentity)

public bool CreateSocketPair(out HSteamNetConnection outConnection1, out HSteamNetConnection outConnection2, bool useNetworkLoopback, in SteamNetworkingIdentity identity1, in SteamNetworkingIdentity identity2)

Parameters

outConnection1 HSteamNetConnection
outConnection2 HSteamNetConnection
useNetworkLoopback bool
identity1 SteamNetworkingIdentity
identity2 SteamNetworkingIdentity

Returns

bool

DestroyPollGroup(HSteamNetPollGroup)

public bool DestroyPollGroup(HSteamNetPollGroup pollGroup)

Parameters

pollGroup HSteamNetPollGroup

Returns

bool

FindRelayAuthTicketForServer(in SteamNetworkingIdentity, int, out SteamDatagramRelayAuthTicket)

public int FindRelayAuthTicketForServer(in SteamNetworkingIdentity identityGameServer, int remoteVirtualPort, out SteamDatagramRelayAuthTicket outParsedTicket)

Parameters

identityGameServer SteamNetworkingIdentity
remoteVirtualPort int
outParsedTicket SteamDatagramRelayAuthTicket

Returns

int

FlushMessagesOnConnection(HSteamNetConnection)

public EResult FlushMessagesOnConnection(HSteamNetConnection conn)

Parameters

conn HSteamNetConnection

Returns

EResult

GetAuthenticationStatus(out SteamNetAuthenticationStatus)

public ESteamNetworkingAvailability GetAuthenticationStatus(out SteamNetAuthenticationStatus details)

Parameters

details SteamNetAuthenticationStatus

Returns

ESteamNetworkingAvailability

GetCertificateRequest(out int, Span<byte>, out string)

public bool GetCertificateRequest(out int blobCount, Span<byte> blob, out string errMsg)

Parameters

blobCount int
blob Span<byte>
errMsg string

Returns

bool

GetConnectionInfo(HSteamNetConnection, out SteamNetConnectionInfo)

public bool GetConnectionInfo(HSteamNetConnection conn, out SteamNetConnectionInfo info)

Parameters

conn HSteamNetConnection
info SteamNetConnectionInfo

Returns

bool

GetConnectionName(HSteamNetConnection, Span<byte>)

public bool GetConnectionName(HSteamNetConnection peer, Span<byte> pszName)

Parameters

peer HSteamNetConnection
pszName Span<byte>

Returns

bool

GetConnectionRealTimeStatus(HSteamNetConnection, out SteamNetConnectionRealTimeStatus, Span<SteamNetConnectionRealTimeLaneStatus>)

public EResult GetConnectionRealTimeStatus(HSteamNetConnection conn, out SteamNetConnectionRealTimeStatus status, Span<SteamNetConnectionRealTimeLaneStatus> lanes)

Parameters

conn HSteamNetConnection
status SteamNetConnectionRealTimeStatus
lanes Span<SteamNetConnectionRealTimeLaneStatus>

Returns

EResult

GetConnectionUserData(HSteamNetConnection)

public long GetConnectionUserData(HSteamNetConnection peer)

Parameters

peer HSteamNetConnection

Returns

long

GetDetailedConnectionStatus(HSteamNetConnection, Span<byte>)

public int GetDetailedConnectionStatus(HSteamNetConnection conn, Span<byte> pszBuf)

Parameters

conn HSteamNetConnection
pszBuf Span<byte>

Returns

int

GetFakeIP(int, out SteamNetworkingFakeIPResult)

public void GetFakeIP(int idxFirstPort, out SteamNetworkingFakeIPResult info)

Parameters

idxFirstPort int
info SteamNetworkingFakeIPResult

GetGameCoordinatorServerLogin(ref SteamDatagramGameCoordinatorServerLogin, out int, Span<byte>)

public EResult GetGameCoordinatorServerLogin(ref SteamDatagramGameCoordinatorServerLogin loginInfo, out int signedBlobCount, Span<byte> blob)

Parameters

loginInfo SteamDatagramGameCoordinatorServerLogin
signedBlobCount int
blob Span<byte>

Returns

EResult

GetHostedDedicatedServerAddress(out SteamDatagramHostedAddress)

public EResult GetHostedDedicatedServerAddress(out SteamDatagramHostedAddress routing)

Parameters

routing SteamDatagramHostedAddress

Returns

EResult

GetHostedDedicatedServerPOPID()

public SteamNetworkingPOPID GetHostedDedicatedServerPOPID()

Returns

SteamNetworkingPOPID

GetHostedDedicatedServerPort()

public ushort GetHostedDedicatedServerPort()

Returns

ushort

GetIdentity(out SteamNetworkingIdentity)

public bool GetIdentity(out SteamNetworkingIdentity identity)

Parameters

identity SteamNetworkingIdentity

Returns

bool

GetListenSocketAddress(HSteamListenSocket, out SteamNetworkingIPAddr)

public bool GetListenSocketAddress(HSteamListenSocket socket, out SteamNetworkingIPAddr address)

Parameters

socket HSteamListenSocket
address SteamNetworkingIPAddr

Returns

bool

GetRemoteFakeIPForConnection(HSteamNetConnection, out SteamNetworkingIPAddr)

public EResult GetRemoteFakeIPForConnection(HSteamNetConnection conn, out SteamNetworkingIPAddr outAddr)

Parameters

conn HSteamNetConnection
outAddr SteamNetworkingIPAddr

Returns

EResult

InitAuthentication()

public ESteamNetworkingAvailability InitAuthentication()

Returns

ESteamNetworkingAvailability

OnSteamNetAuthenticationStatus(CallbackAction<SteamNetAuthenticationStatus>)

public IDisposable OnSteamNetAuthenticationStatus(CallbackAction<SteamNetAuthenticationStatus> func)

Parameters

func CallbackAction<SteamNetAuthenticationStatus>

Returns

IDisposable

OnSteamNetConnectionStatusChangedCallback(CallbackAction<SteamNetConnectionStatusChangedCallback>)

public IDisposable OnSteamNetConnectionStatusChangedCallback(CallbackAction<SteamNetConnectionStatusChangedCallback> func)

Parameters

func CallbackAction<SteamNetConnectionStatusChangedCallback>

Returns

IDisposable

OnSteamNetworkingFakeIPResult(CallbackAction<SteamNetworkingFakeIPResult>)

public IDisposable OnSteamNetworkingFakeIPResult(CallbackAction<SteamNetworkingFakeIPResult> func)

Parameters

func CallbackAction<SteamNetworkingFakeIPResult>

Returns

IDisposable

ReceiveMessagesOnConnection(HSteamNetConnection, Span<SteamNetworkingMessagePtr>)

public int ReceiveMessagesOnConnection(HSteamNetConnection conn, Span<SteamNetworkingMessagePtr> ppOutMessages)

Parameters

conn HSteamNetConnection
ppOutMessages Span<SteamNetworkingMessagePtr>

Returns

int

ReceiveMessagesOnPollGroup(HSteamNetPollGroup, Span<SteamNetworkingMessagePtr>)

public int ReceiveMessagesOnPollGroup(HSteamNetPollGroup pollGroup, Span<SteamNetworkingMessagePtr> ppOutMessages)

Parameters

pollGroup HSteamNetPollGroup
ppOutMessages Span<SteamNetworkingMessagePtr>

Returns

int

ReceivedP2PCustomSignal(ReadOnlySpan<byte>, ref ISteamNetworkingSignalingRecvContext)

public bool ReceivedP2PCustomSignal(ReadOnlySpan<byte> msg, ref ISteamNetworkingSignalingRecvContext context)

Parameters

msg ReadOnlySpan<byte>
context ISteamNetworkingSignalingRecvContext

Returns

bool

ReceivedRelayAuthTicket(ReadOnlySpan<byte>, out SteamDatagramRelayAuthTicket)

public bool ReceivedRelayAuthTicket(ReadOnlySpan<byte> ticket, out SteamDatagramRelayAuthTicket outParsedTicket)

Parameters

ticket ReadOnlySpan<byte>
outParsedTicket SteamDatagramRelayAuthTicket

Returns

bool

ResetIdentity(in SteamNetworkingIdentity)

public void ResetIdentity(in SteamNetworkingIdentity identity)

Parameters

identity SteamNetworkingIdentity

RunCallbacks()

public void RunCallbacks()

SendMessageToConnection(HSteamNetConnection, ReadOnlySpan<byte>, int, out long)

public EResult SendMessageToConnection(HSteamNetConnection conn, ReadOnlySpan<byte> data, int sendFlags, out long outMessageNumber)

Parameters

conn HSteamNetConnection
data ReadOnlySpan<byte>
sendFlags int
outMessageNumber long

Returns

EResult

SendMessages(ReadOnlySpan<SteamNetworkingMessagePtr>, Span<long>)

public void SendMessages(ReadOnlySpan<SteamNetworkingMessagePtr> messages, Span<long> outMessageNumberOrResult)

Parameters

messages ReadOnlySpan<SteamNetworkingMessagePtr>
outMessageNumberOrResult Span<long>

SetCertificate(ReadOnlySpan<byte>, out string)

public bool SetCertificate(ReadOnlySpan<byte> certificate, out string errMsg)

Parameters

certificate ReadOnlySpan<byte>
errMsg string

Returns

bool

SetConnectionName(HSteamNetConnection, string)

public void SetConnectionName(HSteamNetConnection peer, string pszName)

Parameters

peer HSteamNetConnection
pszName string

SetConnectionPollGroup(HSteamNetConnection, HSteamNetPollGroup)

public bool SetConnectionPollGroup(HSteamNetConnection conn, HSteamNetPollGroup pollGroup)

Parameters

conn HSteamNetConnection
pollGroup HSteamNetPollGroup

Returns

bool

SetConnectionUserData(HSteamNetConnection, long)

public bool SetConnectionUserData(HSteamNetConnection peer, long userData)

Parameters

peer HSteamNetConnection
userData long

Returns

bool

UntilAuthentication(CancellationToken)

Initializes authentication and waits until it is ready.

public Promise UntilAuthentication(CancellationToken cancel = default)

Parameters

cancel CancellationToken

Returns

Promise

Resolves ONLY when authentication has been successful.

Remarks

Indicate our desire to be ready participate in authenticated communications. If we are currently not ready, then steps will be taken to obtain the necessary certificates. (This includes a certificate for us, as well as any CA certificates needed to authenticate peers.)

You can call this at program init time if you know that you are going to be making authenticated connections, so that we will be ready immediately when those connections are attempted. (Note that essentially all connections require authentication, with the exception of ordinary UDP connections with authentication disabled using k_ESteamNetworkingConfig_IP_AllowWithoutAuth.) If you don't call this function, we will wait until a feature is utilized that that necessitates these resources.

You can also call this function to force a retry, if failure has occurred. Once we make an attempt and fail, we will not automatically retry. In this respect, the behavior of the system after trying and failing is the same as before the first attempt: attempting authenticated communication or calling this function will call the system to attempt to acquire the necessary resources.

You can use GetAuthenticationStatus(out SteamNetAuthenticationStatus) or listen for SteamNetAuthenticationStatus to monitor the status.