Skip to content

weesleekit/EasySteamSockets

Repository files navigation

EasySteamSockets' Purpose

EasySteamSockets is a library that builds on the Steam socket server networking provided in Facepunch.Steamworks. The sample project is a lightweight WinForm app to demonstrate sending two types of payloads:

Payload Type Example Purpose
"JSON" ChatMessage "JSON" payloads that can easily support complex objects without the developer having to worry about how it is encoded
"Byte" PlayerPositionMessage "Byte" payloads that the developer has more control over how to read and write the bytes

Networking Milestone

How to use

Initial Setup

Note: that the library needs a one-time initialisation by providing it the assembly that has the payloads defined in it.

{
    EasySteamSockets.Initialiser.Initialise(Assembly.GetExecutingAssembly());
}

Sending a message

See FormClient.cs for a fully worked example. The code snippets below are taken from this class.

Note that for byte type payloads that might be sent often, it is possible to re-use messages.

{
    PlayerPositionUpdateMessage playerPositionUpdateMessage = new()
    {
        Id = 123,
        X = x,
        Y = y,
    };

    client?.SendMessage(playerPositionUpdateMessage, SendType.Reliable);
}

Receiving a message

Periodically call Receive on the client or server as appropriate e.g.

    client?.Receive();
    server?.Receive();

Note that the received messages are reused the next time the same type is received therefore don't keep a reference to it.

{   
    client?.Events.Subscribe<ChatMessage>(ChatMessageReceived);
}

private void ChatMessageReceived(ChatMessage chatMessage)
{
    // Consume chatMessage here.
}

About

Steam networking library enhancement for Facepunch.Steamworks

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages