Search code examples
c#network-programmingmonogamelidgren

NetException in Lidgren Framework


What make when happens Lidgren.Network.NetException: "This message has already sent! Use NetPeer.SendMessage() to send multiple recipients efficiently" ?

                                else if (CounfOfPlayers == 1)
                            {
                                Player2Connection = inc.SenderConnection;
                                Console.WriteLine(Player2Connection.RemoteEndPoint.ToString());
                                CounfOfPlayers++;
                                Console.WriteLine("Accepted second player");
                                outmsg.Write((byte)PacketType.RDY);
                                Server.SendMessage(outmsg, Player1Connection, NetDeliveryMethod.ReliableOrdered);
                                Server.SendMessage(outmsg, Player2Connection, NetDeliveryMethod.ReliableOrdered);
                            }

Solution

  • You can only send each NetOutgoingMessage once.

    You should use NetClient.CreateMessage() to create every instance according to this.