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.

Can't get SocketManager to work properly

See original GitHub issue
public class TestClient : ConnectionManager
{
	public override void OnConnecting(ConnectionInfo info)
	{
		Debug.Log("Connecting");
	}

	public override void OnConnected(ConnectionInfo info)
	{
		Debug.Log("Connected");

		string str = "Msg for Server";
		Connection.SendMessage(Marshal.StringToHGlobalUni(str), str.Length * 2 + 1, SendType.Reliable);
	}

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

	public override void OnMessage(IntPtr data, int size, long messageNum, long recvTime, int channel)
	{
		Debug.Log("Msg received: " + Marshal.PtrToStringUni(data));
	}
}
public class TestServer : SocketManager
{
	public override void OnConnecting(Connection connection, ConnectionInfo data)
	{
		connection.Accept();
		Debug.Log($"{data.Identity} is connecting");
	}

	public override void OnConnected(Connection connection, ConnectionInfo data)
	{
		Debug.Log($"{data.Identity} has joined the game");

		string str = "Msg for client";
		connection.SendMessage(Marshal.StringToHGlobalUni(str), str.Length * 2 + 1, SendType.Reliable);
	}

	public override void OnDisconnected(Connection connection, ConnectionInfo data)
	{
		Debug.Log($"{data.Identity} has disconnected");
	}

	public override void OnMessage(Connection connection, NetIdentity identity, IntPtr data, int size, long messageNum, long recvTime, int channel)
	{
		Debug.Log($"We got a message from {identity}!");

		connection.SendMessage(data, size, SendType.Reliable);
	}
}
public class Test : MonoBehaviour
{
	TestServer server;
	TestClient client;

	private void Awake()
	{
		SteamManager.Initialize();

		server = SteamNetworkingSockets.CreateNormalSocket<TestServer>(NetAddress.AnyIp(12345));
		client = SteamNetworkingSockets.ConnectNormal<TestClient>(NetAddress.LocalHost(12345));
	}

	private void Update()
	{
		server.Receive();
		client.Receive();
	}
}

Output in Unity: Connecting ip:[::1]:56920 is connecting ip:[::1]:56920 has joined the game Connected Msg received: Msg for client⤀뚿졚솄嬄ᅠᑄ젪ꗜ訛좘쯱⠶תּ⿩姏㉉鿀흆ɔ

Problem: For some reason the message to the server never triggers the OnMessage method in the TestServer class. Most of the time there are random characters after the message I receive.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bthomas2622commented, Feb 10, 2021

@WilhelmW got a fix! See #467

1reaction
Rohansicommented, Jan 23, 2021

You need to pump messages with Receive() otherwise OnMessage will not be called.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Socket NodeJs SocketManager not pulling through
Issue; I can get the socket working fine. Value from Form fine however I this values are not being pushed over to socketManager....
Read more >
Troubleshooting connection issues
You are trying to reach a plain WebSocket server; The server is not reachable; The client is not compatible with the version of...
Read more >
Socket.IO 3 - Best HTTP/2 Documentation
SocketManager 's Close function closes all sockets, shuts down the transport and no more communication is done to the server. Calling Disconnect on...
Read more >
org.jboss.mq.SpyJMSException: OutOfMemoryError
Hi, I'm using JBossMQ (PTP) and everything seems to be working fine except the fact that during a load test the following error...
Read more >
JBoss on Solaris leaves threads hanging
I tried to enable ClientMonitorInterceptor but that doesn't do anything. This is Jboss 3.2.3 and Soloris 5.8. Clients run on Windows and Linux....
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