ISteamNetworkingSockets

Lower level networking API.

- Connection-oriented API (like TCP, not UDP). When sending and receiving messages, a connection handle is used. (For a UDP-style interface, where the peer is identified by their address with each send/recv call, see ISteamNetworkingMessages.) The typical pattern is for a "server" to "listen" on a "listen socket." A "client" will "connect" to the server, and the server will "accept" the connection. If you have a symmetric situation where either peer may initiate the connection and server/client roles are not clearly defined, check out k_ESteamNetworkingConfig_SymmetricConnect. - But unlike TCP, it's message-oriented, not stream-oriented. - Mix of reliable and unreliable messages - Fragmentation and reassembly - Supports connectivity over plain UDP - Also supports SDR ("Steam Datagram Relay") connections, which are addressed by the identity of the peer. There is a "P2P" use case and a "hosted dedicated server" use case.

Note that neither of the terms "connection" nor "socket" necessarily correspond one-to-one with an underlying UDP socket. An attempt has been made to keep the semantics as similar to the standard socket model when appropriate, but some deviations do exist.

See also: ISteamNetworkingMessages, the UDP-style interface. This API might be easier to use, especially when porting existing UDP code.

extern (C++) abstract
class ISteamNetworkingSockets {}

Members

Functions

AcceptConnection
EResult AcceptConnection(HSteamNetConnection hConn)

Accept an incoming connection that has been received on a listen socket.

BeginAsyncRequestFakeIP
bool BeginAsyncRequestFakeIP(int nNumPorts)

Begin asynchronous process of allocating a fake IPv4 address that other peers can use to contact us via P2P. IP addresses returned by this function are globally unique for a given appid.

CloseConnection
bool CloseConnection(HSteamNetConnection hPeer, int nReason, char* pszDebug, bool bEnableLinger)

Disconnects from the remote host and invalidates the connection handle. Any unread data on the connection is discarded.

CloseListenSocket
bool CloseListenSocket(HSteamListenSocket hSocket)

Destroy a listen socket. All the connections that were accepting on the listen socket are closed ungracefully.

ConnectByIPAddress
HSteamNetConnection ConnectByIPAddress(SteamNetworkingIPAddr address, int nOptions, SteamNetworkingConfigValue_t* pOptions)

Creates a connection and begins talking to a "server" over UDP at the given IPv4 or IPv6 address. The remote host must be listening with a matching call to CreateListenSocketIP on the specified port.

ConnectP2P
HSteamNetConnection ConnectP2P(SteamNetworkingIdentity identityRemote, int nRemoteVirtualPort, int nOptions, SteamNetworkingConfigValue_t* pOptions)

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.)

ConnectP2PCustomSignaling
HSteamNetConnection ConnectP2PCustomSignaling(ISteamNetworkingConnectionSignaling* pSignaling, SteamNetworkingIdentity* pPeerIdentity, int nRemoteVirtualPort, int nOptions, SteamNetworkingConfigValue_t* pOptions)

Create a P2P "client" connection that does signaling over a custom rendezvous/signaling channel.

ConnectToHostedDedicatedServer
HSteamNetConnection ConnectToHostedDedicatedServer(SteamNetworkingIdentity identityTarget, int nRemoteVirtualPort, int nOptions, SteamNetworkingConfigValue_t* pOptions)

Client call to connect to a server hosted in a Valve data center, on the specified virtual port. You must have placed a ticket for this server into the cache, or else this connect attempt will fail! If you are not issuing your own tickets, then to connect to a dedicated server via SDR in auto-ticket mode, use ConnectP2P. (The server must be configured to allow this type of connection by listening using CreateListenSocketP2P.)

CreateFakeUDPPort
ISteamNetworkingFakeUDPPort* CreateFakeUDPPort(int idxFakeServerPort)

Get an interface that can be used like a UDP port to send/receive datagrams to a FakeIP address. This is intended to make it easy to port existing UDP-based code to take advantage of SDR.

CreateHostedDedicatedServerListenSocket
HSteamListenSocket CreateHostedDedicatedServerListenSocket(int nLocalVirtualPort, int nOptions, SteamNetworkingConfigValue_t* pOptions)

Create a listen socket on the specified virtual port. The physical UDP port to use will be determined by the SDR_LISTEN_PORT environment variable. If a UDP port is not configured, this call will fail.

CreateListenSocketIP
HSteamListenSocket CreateListenSocketIP(SteamNetworkingIPAddr localAddress, int nOptions, SteamNetworkingConfigValue_t* pOptions)

Creates a "server" socket that listens for clients to connect to by calling ConnectByIPAddress, over ordinary UDP (IPv4 or IPv6)

CreateListenSocketP2P
HSteamListenSocket CreateListenSocketP2P(int nLocalVirtualPort, int nOptions, SteamNetworkingConfigValue_t* pOptions)

Like CreateListenSocketIP, but clients will connect using ConnectP2P.

CreateListenSocketP2PFakeIP
HSteamListenSocket CreateListenSocketP2PFakeIP(int idxFakePort, int nOptions, SteamNetworkingConfigValue_t* pOptions)

Create a listen socket that will listen for P2P connections sent to our FakeIP. A peer can initiate connections to this listen socket by calling ConnectByIPAddress.

CreatePollGroup
HSteamNetPollGroup CreatePollGroup()

Create a new poll group.

CreateSocketPair
bool CreateSocketPair(HSteamNetConnection* pOutConnection1, HSteamNetConnection* pOutConnection2, bool bUseNetworkLoopback, SteamNetworkingIdentity* pIdentity1, SteamNetworkingIdentity* pIdentity2)

Create a pair of connections that are talking to each other, e.g. a loopback connection. This is very useful for testing, or so that your client/server code can work the same even when you are running a local "server".

DestroyPollGroup
bool DestroyPollGroup(HSteamNetPollGroup hPollGroup)

Destroy a poll group created with CreatePollGroup().

FindRelayAuthTicketForServer
int FindRelayAuthTicketForServer(SteamNetworkingIdentity identityGameServer, int nRemoteVirtualPort, SteamDatagramRelayAuthTicket* pOutParsedTicket)

Search cache for a ticket to talk to the server on the specified virtual port. If found, returns the number of seconds until the ticket expires, and optionally the complete cracked ticket. Returns 0 if we don't have a ticket.

FlushMessagesOnConnection
EResult FlushMessagesOnConnection(HSteamNetConnection hConn)

Flush any messages waiting on the Nagle timer and send them at the next transmission opportunity (often that means right now).

GetAuthenticationStatus
ESteamNetworkingAvailability GetAuthenticationStatus(SteamNetAuthenticationStatus_t* pDetails)

Query our readiness to participate in authenticated communications. A SteamNetAuthenticationStatus_t callback is posted any time this status changes, but you can use this function to query it at any time.

GetCertificateRequest
bool GetCertificateRequest(int* pcbBlob, void* pBlob, SteamNetworkingErrMsg errMsg)

Get blob that describes a certificate request. You can send this to your game coordinator. Upon entry, *pcbBlob should contain the size of the buffer. On successful exit, it will return the number of bytes that were populated. You can pass pBlob=NULL to query for the required size. (512 bytes is a conservative estimate.)

GetConnectionInfo
bool GetConnectionInfo(HSteamNetConnection hConn, SteamNetConnectionInfo_t* pInfo)

Returns basic information about the high-level state of the connection.

GetConnectionName
bool GetConnectionName(HSteamNetConnection hPeer, char* pszName, int nMaxLen)

Fetch connection name. Returns false if handle is invalid

GetConnectionUserData
long GetConnectionUserData(HSteamNetConnection hPeer)

Fetch connection user data. Returns -1 if handle is invalid or if you haven't set any userdata on the connection.

GetDetailedConnectionStatus
int GetDetailedConnectionStatus(HSteamNetConnection hConn, char* pszBuf, int cbBuf)

Returns detailed connection stats in text format. Useful for dumping to a log, etc.

GetFakeIP
void GetFakeIP(int idxFirstPort, SteamNetworkingFakeIPResult_t* pInfo)

Return info about the FakeIP and port(s) that we have been assigned, if any. idxFirstPort is currently reserved and must be zero. Make sure and check SteamNetworkingFakeIPResult_t::m_eResult

GetGameCoordinatorServerLogin
EResult GetGameCoordinatorServerLogin(SteamDatagramGameCoordinatorServerLogin* pLoginInfo, int* pcbSignedBlob, void* pBlob)

Generate an authentication blob that can be used to securely login with your backend, using SteamDatagram_ParseHostedServerLogin. (See steamdatagram_gamecoordinator.h)

GetHostedDedicatedServerAddress
EResult GetHostedDedicatedServerAddress(SteamDatagramHostedAddress* pRouting)

Return info about the hosted server. This contains the PoPID of the server, and opaque routing information that can be used by the relays to send traffic to your server.

GetHostedDedicatedServerPOPID
SteamNetworkingPOPID GetHostedDedicatedServerPOPID()

Returns 0 if SDR_LISTEN_PORT is not set. Otherwise, returns the data center the server is running in. This will be k_SteamDatagramPOPID_dev in non-production environment.

GetHostedDedicatedServerPort
ushort GetHostedDedicatedServerPort()

Returns the value of the SDR_LISTEN_PORT environment variable. This is the UDP server your server will be listening on. This will configured automatically for you in production environments.

GetIdentity
bool GetIdentity(SteamNetworkingIdentity* pIdentity)

Configure multiple outbound messages streams ("lanes") on a connection, and control head-of-line blocking between them. Messages within a given lane are always sent in the order they are queued, but messages from different lanes may be sent out of order. Each lane has its own message number sequence. The first message sent on each lane will be assigned the number 1.

GetListenSocketAddress
bool GetListenSocketAddress(HSteamListenSocket hSocket, SteamNetworkingIPAddr* address)

Returns local IP and port that a listen socket created using CreateListenSocketIP is bound to.

GetQuickConnectionStatus
bool GetQuickConnectionStatus(HSteamNetConnection hConn, SteamNetworkingQuickConnectionStatus* pStats)

Returns a small set of information about the real-time state of the connection Returns false if the connection handle is invalid, or the connection has ended.

GetRemoteFakeIPForConnection
EResult GetRemoteFakeIPForConnection(HSteamNetConnection hConn, SteamNetworkingIPAddr* pOutAddr)

If the connection was initiated using the "FakeIP" system, then we we can get an IP address for the remote host. If the remote host had a global FakeIP at the time the connection was established, this function will return that global IP. Otherwise, a FakeIP that is unique locally will be allocated from the local FakeIP address space, and that will be returned.

InitAuthentication
ESteamNetworkingAvailability InitAuthentication()

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.)

ReceiveMessagesOnConnection
int ReceiveMessagesOnConnection(HSteamNetConnection hConn, SteamNetworkingMessage_t** ppOutMessages, int nMaxMessages)

Fetch the next available message(s) from the connection, if any. Returns the number of messages returned into your array, up to nMaxMessages. If the connection handle is invalid, -1 is returned.

ReceiveMessagesOnPollGroup
int ReceiveMessagesOnPollGroup(HSteamNetPollGroup hPollGroup, SteamNetworkingMessage_t** ppOutMessages, int nMaxMessages)

Same as ReceiveMessagesOnConnection, but will return the next messages available on any connection in the poll group. Examine SteamNetworkingMessage_t::m_conn to know which connection. (SteamNetworkingMessage_t::m_nConnUserData might also be useful.)

ReceivedP2PCustomSignal
bool ReceivedP2PCustomSignal(void* pMsg, int cbMsg, ISteamNetworkingSignalingRecvContext* pContext)

Called when custom signaling has received a message. When your signaling channel receives a message, it should save off whatever routing information was in the envelope into the context object, and then pass the payload to this function.

ReceivedRelayAuthTicket
bool ReceivedRelayAuthTicket(void* pvTicket, int cbTicket, SteamDatagramRelayAuthTicket* pOutParsedTicket)

Call this when you receive a ticket from your backend / matchmaking system. Puts the ticket into a persistent cache, and optionally returns the parsed ticket.

ResetIdentity
void ResetIdentity(SteamNetworkingIdentity* pIdentity)

Reset the identity associated with this instance. Any open connections are closed. Any previous certificates, etc are discarded. You can pass a specific identity that you want to use, or you can pass NULL, in which case the identity will be invalid until you set it using SetCertificate

RunCallbacks
void RunCallbacks()

Invoke all callback functions queued for this interface. See k_ESteamNetworkingConfig_Callback_ConnectionStatusChanged, etc

SendMessageToConnection
EResult SendMessageToConnection(HSteamNetConnection hConn, void* pData, uint cbData, int nSendFlags, long* pOutMessageNumber)

Send a message to the remote host on the specified connection.

SendMessages
void SendMessages(int nMessages, const(SteamNetworkingMessage_t*)* pMessages, long* pOutMessageNumberOrResult)

Send one or more messages without copying the message payload. This is the most efficient way to send messages. To use this function, you must first allocate a message object using ISteamNetworkingUtils::AllocateMessage. (Do not declare one on the stack or allocate your own.)

SetCertificate
bool SetCertificate(void* pCertificate, int cbCertificate, SteamNetworkingErrMsg errMsg)

Set the certificate. The certificate blob should be the output of SteamDatagram_CreateCert.

SetConnectionName
void SetConnectionName(HSteamNetConnection hPeer, char* pszName)

Set a name for the connection, used mostly for debugging

SetConnectionPollGroup
bool SetConnectionPollGroup(HSteamNetConnection hConn, HSteamNetPollGroup hPollGroup)

Assign a connection to a poll group. Note that a connection may only belong to a single poll group. Adding a connection to a poll group implicitly removes it from any other poll group it is in.

SetConnectionUserData
bool SetConnectionUserData(HSteamNetConnection hPeer, long nUserData)

Set connection user data. the data is returned in the following places - You can query it using GetConnectionUserData. - The SteamNetworkingmessage_t structure. - The SteamNetConnectionInfo_t structure. (Which is a member of SteamNetConnectionStatusChangedCallback_t -- but see WARNINGS below!!!!)

Meta