This message has already been sent!

460 views
Skip to first unread message

Jocke

unread,
Nov 10, 2011, 8:30:11 AM11/10/11
to lidgren-network-gen3
Hi, I'm getting this exception (at random) when I try to send a
message from a Client to my Server.

NetException was unhandled by user code
This message has already been sent! Use NetPeer.SendMessage() to send
to multiple recipients efficiently

It's being thrown from 'client.SendMessage'. What should I do to solve
it?


::GameClient.cs
public void SendClientSpatial(Vector3 position, Vector3 velocity,
Vector3 angle)
{
client.Writer.WriteNewMessage();
client.Writer.Write((byte)GameClientMessageType.ClientSpatial);
messageHelper.WriteVector3(position, client.Writer);
messageHelper.WriteVector3(velocity, client.Writer);
messageHelper.WriteVector3(angle, client.Writer);
client.Send(MessageDeliveryMethod.UnreliableSequenced);
}


:: LidgrenClient.cs
public void Send(MessageDeliveryMethod method)
{
client.SendMessage((NetOutgoingMessage)Writer.GetMessage(),

GetDeliveryMethod(method));
}

lidgren

unread,
Nov 10, 2011, 8:58:14 AM11/10/11
to lidgren-network-gen3
Like the exception states you must not send the NetOutgoingMessage
instance multiple times; but rather allocate a new one using
NetClient.CreateMessage() for each message you send.

--michael

Johannes Eski

unread,
Aug 5, 2013, 8:04:46 PM8/5/13
to lidgren-ne...@googlegroups.com
So is this wrong style, as I get same message?

        public static void broadcastQuitter(int sID, int tID, int pID, bool isKick)
        {
            NetOutgoingMessage outmsg = Vars.server.CreateMessage();
            outmsg.Write((byte)21);

            outmsg.Write(tID);
            outmsg.Write(pID);
            outmsg.Write(isKick);

            for (int i = 0; i < 2; i++)
                for (int j = 0; j < MatchManager.matches[sID].maxPlayers; j++)
                    if (MatchManager.matches[sID].users[i, j].pID > 0 && MatchManager.matches[sID].users[i, j].connection != null)
                        Vars.server.SendMessage(outmsg, MatchManager.matches[sID].users[i, j].connection, NetDeliveryMethod.ReliableOrdered, 3);
        }

In this, Im broadcasting same message to multiple persons. Do I need to re-create message again, after I've sent it to one player?
I'm aware of SendToAll function, but in my case, I really can't use it, becouse gameserver have multiple rooms, and I just want to send specific users, depending what room they are.

Johnathan Free Wortley

unread,
Aug 5, 2013, 9:45:33 PM8/5/13
to lidgren-ne...@googlegroups.com
This is because Lidgren automatically recycles messages on send. Here's another thread where Mike outlines a solution.

Something like:

var connections = new List<NetConnection>();
for (int i = 0; i < 2; i++)
    for (int j = 0; j < MatchManager.matches[sID].maxPlayers; j++)
        if (MatchManager.matches[sID].users[i, j].pID > 0 && MatchManager.matches[sID].users[i, j].connection != null)
            connections.Add(MatchManager.matches[sID].users[i, j].connection);
Vars.server.SendMessage(outmsg, connections, NetDeliveryMethod.ReliableOrdered, 3);

Not sure of the exact overloads, but that's what you'll want to shoot for. Otherwise extract your writes into a method and just call that method instead of server.SendMessage();

Johnathan Free Wortley
--



--
You received this message because you are subscribed to the Google Groups "lidgren-network-gen3" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lidgren-network-...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

lidgren

unread,
Aug 6, 2013, 2:29:27 AM8/6/13
to lidgren-ne...@googlegroups.com
As Johannes writes, you can only send a message to one recipient - it's recycled automatically.

If you know you will send the exact same message to many recipients, but can't use the SendMessage(msg, List<>...) method - you can still save the content, to avoid the overhead of writing each entry again. Something like this:

var msg = peer.CreateMessage();

// write stuff to msg here

var saved = new byte[msg.LengthBytes];
Buffer.BlockCopy(msg.Data, 0, saved, 0, msg.LengthBytes);
var savedBitLength = msg.LengthBits;

// send msg, then null it out

// at a later stage, when you want to sent the message again:
var another = peer.CreateMessage();
another.Write(saved);
another.LengthBits = savedBitLength;

--michael
Reply all
Reply to author
Forward
0 new messages