- Home /
NetworkError.WrongConnection when sending messages
(Context) I'm trying to make a game that has both a singleplayer mode, wich is already completed, and a multiplayer. To get the basics of the multiplayer going, I started working on a way to display what users are online in a server using the NetworkTransport class. I'll later add the rest of the multiplayer part.
Everyting seems to work when I connect but when I try to send a message to the server, the Send method returns error 2, wich is NetworkError.WrongConnection
. I save everything when I start the client:
NetworkTransport.Init();
ConnectionConfig cc = new ConnectionConfig();
reliableChannel = cc.AddChannel(QosType.Reliable);
unreliableChannel = cc.AddChannel(QosType.Unreliable);
HostTopology topo = new HostTopology(cc, MaxUsers);
//Clinet only
hostId = NetworkTransport.AddHost(topo, 0);
connectionId = NetworkTransport.Connect(hostId, serverIp, Port, 0, out error);
and I use these parameters when sending the message:
byte[] buffer = new byte[byteSize]; //data itself
//convert to byte array
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream memStream = new MemoryStream(buffer);
formatter.Serialize(memStream, msg);
//sending
NetworkTransport.Send(hostId, connectionId, channelId, buffer, byteSize, out error);
Debug.Log($"Sent a message with error code {error}");
and the output I get on the client is:
Sent a message with error code 2
And on the server I get nothing.
I made the server Log whenever it recieves a data message: Debug.Log("Recieved data message");
Is there anything I can do? Do I need to show more code?. thanks in advance.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Network Tutorial Interpolation - TPS Auth 0 Answers
The magic key to networking? 0 Answers
[HELP]Photon multiple Prefabs/Characters 0 Answers