question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SteamNetworkingSocket not receiving messages

See original GitHub issue

Describe the bug I’m not receiving messages, what am I doing wrong?

I’m also calling socketManager.Receive(); every frame.(it doesn’t matter if I do this or not) but I only get the OnConnecting, OnConnected, and OnDisconnected messages.

To Reproduce Steps to reproduce the behavior:

  1. try this code(it is in unity)
  2. see that “OK” gets logged for every connection*buttonpress
  3. see that there are no messages incoming

Calling Code this is my interface:

public class SteamSocketManagerInterface : ISocketManager
{
    public void OnConnected(Connection connection, ConnectionInfo info)
    {
        Debug.Log("OnConnected!!");
    }

    public void OnConnecting(Connection connection, ConnectionInfo info)
    {
        connection.Accept();
        Debug.Log("OnConnecting!!");
    }

    public void OnDisconnected(Connection connection, ConnectionInfo info)
    {
        Debug.Log("OnDisconnected!!");
    }

    public void OnMessage(Connection connection, NetIdentity identity, IntPtr data, int size, long messageNum, long recvTime, int channel)
    {
        Debug.Log("Got A Message!!");
    }
}

this is how I try to use it:

socketManager = SteamNetworkingSockets.CreateRelaySocket<SocketManager>();
socketManager.Interface = new SteamSocketManagerInterface();
SteamNetworkingSockets.ConnectRelay<ConnectionManager>(SteamClient.SteamId);

and later on in the code, on a button press:

for (int i = 0; i < socketManager.Connected.Count; i++)
        {
            Result result = socketManager.Connected[i].SendMessage(bytes, sendType);
            Debug.Log(result);
        }

Expected behavior I expected to get a message.

Desktop (please complete the following information):

  • OS: Windows10
  • Unity: Unity 2019.4.0f1

Additional context I first made a class derive from SocketManager but this didn’t work and I read that it needs to be an interface to receive messages, so I tried it with this simple interface. there is also additional code so other people can join my lobby and connect with me, but I also don’t receive messages from them.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19

github_iconTop GitHub Comments

1reaction
bthomas2622commented, Feb 3, 2021

@Scarso327 connecting through relays. Thanks so much for helping. I posted a new issue trying to explain where I’m at: https://github.com/Facepunch/Facepunch.Steamworks/issues/529

The way I have it set up in my 1v1 game is 1 host sets up the socket manager as a server and then their own connection manager to connect to it. And their opponent just has a connection manager. But I’ve been unable to send messages from connection manager to socket manager from either host or joining person.

1reaction
ikomhoogcommented, Jul 18, 2020

“SocketManager’s Recieve will handle messages from ALL connections so you don’t have to loop through all connections or something like that.” thats what i also thought, but it doesnt work like you described in my code. i need to call connectionManager.Receive() to get anything, socketManager.Receive doesnt do anything(for me). Please try this code:

using System;
using Steamworks;
using Steamworks.Data;
using UnityEngine;

public class SteamNetworkingTest : MonoBehaviour
{
    public SteamSocketManager socketManager;
    public SteamConnectionManager connectionManager;

    void Start()
    {
        SteamClient.Init(480);
        SteamNetworkingUtils.InitRelayNetworkAccess();
        Debug.Log("logged in as: " + SteamClient.Name);
        socketManager = SteamNetworkingSockets.CreateRelaySocket<SteamSocketManager>();
        connectionManager = SteamNetworkingSockets.ConnectRelay<SteamConnectionManager>(SteamClient.SteamId);
    }

    // Update is called once per frame
    void Update()
    {
        socketManager.Receive();
        //connectionManager.Receive();
        for (int i = 0; i < socketManager.Connected.Count; i++)
        {
            Debug.Log(socketManager.Connected[i].SendMessage("Hello"));
        }
    }

    void OnApplicationQuit()
    {
        SteamClient.Shutdown();
        Debug.Log("Shutdown");
    }
}

public class SteamSocketManager : SocketManager
{
    public override void OnConnected(Connection connection, ConnectionInfo info)
    {
        Debug.Log("SocketOnConnected");
    }

    public override void OnConnecting(Connection connection, ConnectionInfo info)
    {
        connection.Accept();
        Debug.Log("SocketOnConnecting");
    }

    public override void OnDisconnected(Connection connection, ConnectionInfo info)
    {
        Debug.Log("SocketOnDisconnected");
    }

    public override void OnMessage(Connection connection, NetIdentity identity, IntPtr data, int size, long messageNum, long recvTime, int channel)
    {
        Debug.Log("Socket Got A Message");
    }
}

public class SteamConnectionManager : ConnectionManager
{
    public override void OnConnected(ConnectionInfo info)
    {
        Debug.Log("ConnectionOnConnected");
    }

    public override void OnConnecting(ConnectionInfo info)
    {
        Debug.Log("ConnectionOnConnecting");
    }

    public override void OnDisconnected(ConnectionInfo info)
    {
        Debug.Log("ConnectionOnDisconnected");
    }

    public override void OnMessage(IntPtr data, int size, long messageNum, long recvTime, int channel)
    {
        Debug.Log("Connection Got A Message");
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Waited "X" ms for SteamNetworkingSockets lock ...
I am getting lags since today and in my console are error messages like this Waited 16.3ms for SteamNetworkingSockets lock [ServiceThread] ...
Read more >
"SteamNetworkingSockets lock held for X ms (Performance ...
The error messages stop to occur when I keep "fps_max" set to about 120-200. They still show up sometimes but much less frequently...
Read more >
Steamnetworkingsockets.dll Download: Fix DLL Missing or ...
Download the Steamnetworkingsockets.dll file for free and fix Steamnetworkingsockets.dll Missing or Was Not Found Error on Windows.
Read more >
ISteamNetworkingSockets Interface
It's a connection-oriented API (like TCP, not UDP). When sending and receiving messages, the peer is identified using a connection handle.
Read more >
steamnetworkingsockets.dll free download
Download steamnetworkingsockets.dll free! Fix DLL missing error. Solve it yourself or get help using DLL‑files.com Client to fix DLL error automatically.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found