C# Класс Steamworks.SteamGameServerNetworking

Показать файл Открыть проект

Открытые методы

Метод Описание
AcceptP2PSessionWithUser ( CSteamID steamIDRemote ) : bool

AcceptP2PSessionWithUser() should only be called in response to a P2PSessionRequest_t callback

P2PSessionRequest_t will be posted if another user tries to send you a packet that you haven't talked to yet

if you don't want to talk to the user, just ignore the request

if the user continues to send you packets, another P2PSessionRequest_t will be posted periodically

this may be called multiple times for a single user

(if you've called SendP2PPacket() on the other user, this implicitly accepts the session request)

AllowP2PPacketRelay ( bool bAllow ) : bool

Allow P2P connections to fall back to being relayed through the Steam servers if a direct connection

or NAT-traversal cannot be established. Only applies to connections created after setting this value,

or to existing connections that need to automatically reconnect after this value is set.

P2P packet relay is allowed by default

CloseP2PChannelWithUser ( CSteamID steamIDRemote, int nChannel ) : bool

call CloseP2PChannelWithUser() when you're done talking to a user on a specific channel. Once all channels

open channels to a user have been closed, the open session to the user will be closed and new data from this

user will trigger a P2PSessionRequest_t callback

CloseP2PSessionWithUser ( CSteamID steamIDRemote ) : bool

call CloseP2PSessionWithUser() when you're done talking to a user, will free up resources under-the-hood

if the remote user tries to send data to you again, another P2PSessionRequest_t callback will be posted

CreateConnectionSocket ( uint nIP, ushort nPort, int nTimeoutSec ) : SNetSocket_t
CreateListenSocket ( int nVirtualP2PPort, uint nIP, ushort nPort, bool bAllowUseOfPacketRelay ) : SNetListenSocket_t

//////////////////////////////////////////////////////////////////////////////////////////

LISTEN / CONNECT style interface functions

This is an older set of functions designed around the Berkeley TCP sockets model

it's preferential that you use the above P2P functions, they're more robust

and these older functions will be removed eventually

//////////////////////////////////////////////////////////////////////////////////////////

creates a socket and listens others to connect

will trigger a SocketStatusCallback_t callback on another client connecting

nVirtualP2PPort is the unique ID that the client will connect to, in case you have multiple ports

this can usually just be 0 unless you want multiple sets of connections

unIP is the local IP address to bind to

pass in 0 if you just want the default local IP

unPort is the port to use

pass in 0 if you don't want users to be able to connect via IP/Port, but expect to be always peer-to-peer connections only

CreateP2PConnectionSocket ( CSteamID steamIDTarget, int nVirtualPort, int nTimeoutSec, bool bAllowUseOfPacketRelay ) : SNetSocket_t

creates a socket and begin connection to a remote destination

can connect via a known steamID (client or game server), or directly to an IP

on success will trigger a SocketStatusCallback_t callback

on failure or timeout will trigger a SocketStatusCallback_t callback with a failure code in m_eSNetSocketState

DestroyListenSocket ( SNetListenSocket_t hSocket, bool bNotifyRemoteEnd ) : bool

destroying a listen socket will automatically kill all the regular sockets generated from it

DestroySocket ( SNetSocket_t hSocket, bool bNotifyRemoteEnd ) : bool

disconnects the connection to the socket, if any, and invalidates the handle

any unread data on the socket will be thrown away

if bNotifyRemoteEnd is set, socket will not be completely destroyed until the remote end acknowledges the disconnect

GetListenSocketInfo ( SNetListenSocket_t hListenSocket, uint &pnIP, ushort &pnPort ) : bool

returns which local port the listen socket is bound to

*pnIP and *pnPort will be 0 if the socket is set to listen for P2P connections only

GetMaxPacketSize ( SNetSocket_t hSocket ) : int

max packet size, in bytes

GetP2PSessionState ( CSteamID steamIDRemote, P2PSessionState_t &pConnectionState ) : bool

fills out P2PSessionState_t structure with details about the underlying connection to the user

should only needed for debugging purposes

returns false if no connection exists to the specified user

GetSocketConnectionType ( SNetSocket_t hSocket ) : ESNetSocketConnectionType

returns true to describe how the socket ended up connecting

GetSocketInfo ( SNetSocket_t hSocket, CSteamID &pSteamIDRemote, int &peSocketStatus, uint &punIPRemote, ushort &punPortRemote ) : bool

returns information about the specified socket, filling out the contents of the pointers

IsDataAvailable ( SNetListenSocket_t hListenSocket, uint &pcubMsgSize, SNetSocket_t &phSocket ) : bool

checks for data from any socket that has been connected off this listen socket

returns false if there is no data remaining

fills out *pcubMsgSize with the size of the next message, in bytes

fills out *phSocket with the socket that data is available on

IsDataAvailableOnSocket ( SNetSocket_t hSocket, uint &pcubMsgSize ) : bool

receiving data

returns false if there is no data remaining

fills out *pcubMsgSize with the size of the next message, in bytes

IsP2PPacketAvailable ( uint &pcubMsgSize, int nChannel ) : bool

returns true if any data is available for read, and the amount of data that will need to be read

ReadP2PPacket ( byte pubDest, uint cubDest, uint &pcubMsgSize, CSteamID &psteamIDRemote, int nChannel ) : bool

reads in a packet that has been sent from another user via SendP2PPacket()

returns the size of the message and the steamID of the user who sent it in the last two parameters

if the buffer passed in is too small, the message will be truncated

this call is not blocking, and will return false if no data is available

RetrieveData ( SNetListenSocket_t hListenSocket, byte pubDest, uint cubDest, uint &pcubMsgSize, SNetSocket_t &phSocket ) : bool

retrieves data from any socket that has been connected off this listen socket

fills in pubDest with the contents of the message

messages are always complete, of the same size as was sent (i.e. packetized, not streaming)

if *pcubMsgSize < cubDest, only partial data is written

returns false if no data is available

fills out *phSocket with the socket that data is available on

RetrieveDataFromSocket ( SNetSocket_t hSocket, byte pubDest, uint cubDest, uint &pcubMsgSize ) : bool

fills in pubDest with the contents of the message

messages are always complete, of the same size as was sent (i.e. packetized, not streaming)

if *pcubMsgSize < cubDest, only partial data is written

returns false if no data is available

SendDataOnSocket ( SNetSocket_t hSocket, byte pubData, uint cubData, bool bReliable ) : bool

sending data

must be a handle to a connected socket

data is all sent via UDP, and thus send sizes are limited to 1200 bytes; after this, many routers will start dropping packets

use the reliable flag with caution; although the resend rate is pretty aggressive,

it can still cause stalls in receiving data (like TCP)

SendP2PPacket ( CSteamID steamIDRemote, byte pubData, uint cubData, EP2PSend eP2PSendType, int nChannel ) : bool

//////////////////////////////////////////////////////////////////////////////////////////

Session-less connection functions

automatically establishes NAT-traversing or Relay server connections

Sends a P2P packet to the specified user

UDP-like, unreliable and a max packet size of 1200 bytes

the first packet send may be delayed as the NAT-traversal code runs

if we can't get through to the user, an error will be posted via the callback P2PSessionConnectFail_t

see EP2PSend enum above for the descriptions of the different ways of sending packets

nChannel is a routing number you can use to help route message to different systems - you'll have to call ReadP2PPacket()

with the same channel number in order to retrieve the data on the other end

using different channels to talk to the same user will still use the same underlying p2p connection, saving on resources

Описание методов

AcceptP2PSessionWithUser() публичный статический Метод

AcceptP2PSessionWithUser() should only be called in response to a P2PSessionRequest_t callback

P2PSessionRequest_t will be posted if another user tries to send you a packet that you haven't talked to yet

if you don't want to talk to the user, just ignore the request

if the user continues to send you packets, another P2PSessionRequest_t will be posted periodically

this may be called multiple times for a single user

(if you've called SendP2PPacket() on the other user, this implicitly accepts the session request)

public static AcceptP2PSessionWithUser ( CSteamID steamIDRemote ) : bool
steamIDRemote CSteamID
Результат bool

AllowP2PPacketRelay() публичный статический Метод

Allow P2P connections to fall back to being relayed through the Steam servers if a direct connection

or NAT-traversal cannot be established. Only applies to connections created after setting this value,

or to existing connections that need to automatically reconnect after this value is set.

P2P packet relay is allowed by default

public static AllowP2PPacketRelay ( bool bAllow ) : bool
bAllow bool
Результат bool

CloseP2PChannelWithUser() публичный статический Метод

call CloseP2PChannelWithUser() when you're done talking to a user on a specific channel. Once all channels

open channels to a user have been closed, the open session to the user will be closed and new data from this

user will trigger a P2PSessionRequest_t callback

public static CloseP2PChannelWithUser ( CSteamID steamIDRemote, int nChannel ) : bool
steamIDRemote CSteamID
nChannel int
Результат bool

CloseP2PSessionWithUser() публичный статический Метод

call CloseP2PSessionWithUser() when you're done talking to a user, will free up resources under-the-hood

if the remote user tries to send data to you again, another P2PSessionRequest_t callback will be posted

public static CloseP2PSessionWithUser ( CSteamID steamIDRemote ) : bool
steamIDRemote CSteamID
Результат bool

CreateConnectionSocket() публичный статический Метод

public static CreateConnectionSocket ( uint nIP, ushort nPort, int nTimeoutSec ) : SNetSocket_t
nIP uint
nPort ushort
nTimeoutSec int
Результат SNetSocket_t

CreateListenSocket() публичный статический Метод

//////////////////////////////////////////////////////////////////////////////////////////

LISTEN / CONNECT style interface functions

This is an older set of functions designed around the Berkeley TCP sockets model

it's preferential that you use the above P2P functions, they're more robust

and these older functions will be removed eventually

//////////////////////////////////////////////////////////////////////////////////////////

creates a socket and listens others to connect

will trigger a SocketStatusCallback_t callback on another client connecting

nVirtualP2PPort is the unique ID that the client will connect to, in case you have multiple ports

this can usually just be 0 unless you want multiple sets of connections

unIP is the local IP address to bind to

pass in 0 if you just want the default local IP

unPort is the port to use

pass in 0 if you don't want users to be able to connect via IP/Port, but expect to be always peer-to-peer connections only

public static CreateListenSocket ( int nVirtualP2PPort, uint nIP, ushort nPort, bool bAllowUseOfPacketRelay ) : SNetListenSocket_t
nVirtualP2PPort int
nIP uint
nPort ushort
bAllowUseOfPacketRelay bool
Результат SNetListenSocket_t

CreateP2PConnectionSocket() публичный статический Метод

creates a socket and begin connection to a remote destination

can connect via a known steamID (client or game server), or directly to an IP

on success will trigger a SocketStatusCallback_t callback

on failure or timeout will trigger a SocketStatusCallback_t callback with a failure code in m_eSNetSocketState

public static CreateP2PConnectionSocket ( CSteamID steamIDTarget, int nVirtualPort, int nTimeoutSec, bool bAllowUseOfPacketRelay ) : SNetSocket_t
steamIDTarget CSteamID
nVirtualPort int
nTimeoutSec int
bAllowUseOfPacketRelay bool
Результат SNetSocket_t

DestroyListenSocket() публичный статический Метод

destroying a listen socket will automatically kill all the regular sockets generated from it

public static DestroyListenSocket ( SNetListenSocket_t hSocket, bool bNotifyRemoteEnd ) : bool
hSocket SNetListenSocket_t
bNotifyRemoteEnd bool
Результат bool

DestroySocket() публичный статический Метод

disconnects the connection to the socket, if any, and invalidates the handle

any unread data on the socket will be thrown away

if bNotifyRemoteEnd is set, socket will not be completely destroyed until the remote end acknowledges the disconnect

public static DestroySocket ( SNetSocket_t hSocket, bool bNotifyRemoteEnd ) : bool
hSocket SNetSocket_t
bNotifyRemoteEnd bool
Результат bool

GetListenSocketInfo() публичный статический Метод

returns which local port the listen socket is bound to

*pnIP and *pnPort will be 0 if the socket is set to listen for P2P connections only

public static GetListenSocketInfo ( SNetListenSocket_t hListenSocket, uint &pnIP, ushort &pnPort ) : bool
hListenSocket SNetListenSocket_t
pnIP uint
pnPort ushort
Результат bool

GetMaxPacketSize() публичный статический Метод

max packet size, in bytes

public static GetMaxPacketSize ( SNetSocket_t hSocket ) : int
hSocket SNetSocket_t
Результат int

GetP2PSessionState() публичный статический Метод

fills out P2PSessionState_t structure with details about the underlying connection to the user

should only needed for debugging purposes

returns false if no connection exists to the specified user

public static GetP2PSessionState ( CSteamID steamIDRemote, P2PSessionState_t &pConnectionState ) : bool
steamIDRemote CSteamID
pConnectionState P2PSessionState_t
Результат bool

GetSocketConnectionType() публичный статический Метод

returns true to describe how the socket ended up connecting

public static GetSocketConnectionType ( SNetSocket_t hSocket ) : ESNetSocketConnectionType
hSocket SNetSocket_t
Результат ESNetSocketConnectionType

GetSocketInfo() публичный статический Метод

returns information about the specified socket, filling out the contents of the pointers

public static GetSocketInfo ( SNetSocket_t hSocket, CSteamID &pSteamIDRemote, int &peSocketStatus, uint &punIPRemote, ushort &punPortRemote ) : bool
hSocket SNetSocket_t
pSteamIDRemote CSteamID
peSocketStatus int
punIPRemote uint
punPortRemote ushort
Результат bool

IsDataAvailable() публичный статический Метод

checks for data from any socket that has been connected off this listen socket

returns false if there is no data remaining

fills out *pcubMsgSize with the size of the next message, in bytes

fills out *phSocket with the socket that data is available on

public static IsDataAvailable ( SNetListenSocket_t hListenSocket, uint &pcubMsgSize, SNetSocket_t &phSocket ) : bool
hListenSocket SNetListenSocket_t
pcubMsgSize uint
phSocket SNetSocket_t
Результат bool

IsDataAvailableOnSocket() публичный статический Метод

receiving data

returns false if there is no data remaining

fills out *pcubMsgSize with the size of the next message, in bytes

public static IsDataAvailableOnSocket ( SNetSocket_t hSocket, uint &pcubMsgSize ) : bool
hSocket SNetSocket_t
pcubMsgSize uint
Результат bool

IsP2PPacketAvailable() публичный статический Метод

returns true if any data is available for read, and the amount of data that will need to be read

public static IsP2PPacketAvailable ( uint &pcubMsgSize, int nChannel ) : bool
pcubMsgSize uint
nChannel int
Результат bool

ReadP2PPacket() публичный статический Метод

reads in a packet that has been sent from another user via SendP2PPacket()

returns the size of the message and the steamID of the user who sent it in the last two parameters

if the buffer passed in is too small, the message will be truncated

this call is not blocking, and will return false if no data is available

public static ReadP2PPacket ( byte pubDest, uint cubDest, uint &pcubMsgSize, CSteamID &psteamIDRemote, int nChannel ) : bool
pubDest byte
cubDest uint
pcubMsgSize uint
psteamIDRemote CSteamID
nChannel int
Результат bool

RetrieveData() публичный статический Метод

retrieves data from any socket that has been connected off this listen socket

fills in pubDest with the contents of the message

messages are always complete, of the same size as was sent (i.e. packetized, not streaming)

if *pcubMsgSize < cubDest, only partial data is written

returns false if no data is available

fills out *phSocket with the socket that data is available on

public static RetrieveData ( SNetListenSocket_t hListenSocket, byte pubDest, uint cubDest, uint &pcubMsgSize, SNetSocket_t &phSocket ) : bool
hListenSocket SNetListenSocket_t
pubDest byte
cubDest uint
pcubMsgSize uint
phSocket SNetSocket_t
Результат bool

RetrieveDataFromSocket() публичный статический Метод

fills in pubDest with the contents of the message

messages are always complete, of the same size as was sent (i.e. packetized, not streaming)

if *pcubMsgSize < cubDest, only partial data is written

returns false if no data is available

public static RetrieveDataFromSocket ( SNetSocket_t hSocket, byte pubDest, uint cubDest, uint &pcubMsgSize ) : bool
hSocket SNetSocket_t
pubDest byte
cubDest uint
pcubMsgSize uint
Результат bool

SendDataOnSocket() публичный статический Метод

sending data

must be a handle to a connected socket

data is all sent via UDP, and thus send sizes are limited to 1200 bytes; after this, many routers will start dropping packets

use the reliable flag with caution; although the resend rate is pretty aggressive,

it can still cause stalls in receiving data (like TCP)

public static SendDataOnSocket ( SNetSocket_t hSocket, byte pubData, uint cubData, bool bReliable ) : bool
hSocket SNetSocket_t
pubData byte
cubData uint
bReliable bool
Результат bool

SendP2PPacket() публичный статический Метод

//////////////////////////////////////////////////////////////////////////////////////////

Session-less connection functions

automatically establishes NAT-traversing or Relay server connections

Sends a P2P packet to the specified user

UDP-like, unreliable and a max packet size of 1200 bytes

the first packet send may be delayed as the NAT-traversal code runs

if we can't get through to the user, an error will be posted via the callback P2PSessionConnectFail_t

see EP2PSend enum above for the descriptions of the different ways of sending packets

nChannel is a routing number you can use to help route message to different systems - you'll have to call ReadP2PPacket()

with the same channel number in order to retrieve the data on the other end

using different channels to talk to the same user will still use the same underlying p2p connection, saving on resources

public static SendP2PPacket ( CSteamID steamIDRemote, byte pubData, uint cubData, EP2PSend eP2PSendType, int nChannel ) : bool
steamIDRemote CSteamID
pubData byte
cubData uint
eP2PSendType EP2PSend
nChannel int
Результат bool