Can't get SocketManager to work properly
See original GitHub issuepublic 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:
- Created 3 years ago
- Comments:8 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@WilhelmW got a fix! See #467
You need to pump messages with
Receive()
otherwiseOnMessage
will not be called.