public void Send(Peer peer, short opcode, ISerializablePacket packet) { if (peer == null || !peer.IsConnected) { return; } using (PooledNetWriter w = NetWriterPool.GetWriter()) { MessageHelper.CreateAndFinalize(w, opcode, packet); var segment = w.ToArraySegment(); if (NetLogFilter.messageDiagnostics) { NetDiagnostics.OnSend(opcode, segment.Count, 1); } if (!isSimulated) { peer.SendMessage(segment, UDPTransport.Source.Server); } else { peer.SendSimulatedMessage(segment, UDPTransport.Source.Server); } } }
public void Send(short opcode, ISerializablePacket packet) { using (PooledNetWriter w = NetWriterPool.GetWriter()) { MessageHelper.CreateAndFinalize(w, opcode, packet); var segment = w.ToArraySegment(); if (NetLogFilter.messageDiagnostics) { NetDiagnostics.OnSend(opcode, segment.Count, connectedPeers.Values.Count); } if (!isSimulated) { foreach (var peer in connectedPeers.Values) { peer.SendMessage(segment, UDPTransport.Source.Server); } } else { foreach (var peer in connectedPeers.Values) { peer.SendSimulatedMessage(segment, UDPTransport.Source.Server); } } } }
public static PooledNetWriter GetWriter() { if (pool.Count != 0) { PooledNetWriter writer = pool.Pop(); // reset cached writer length and position writer.SetLength(0); return writer; } return new PooledNetWriter(); }
/// <summary> /// Sends a message to server. /// </summary> /// <param name="msg"></param> /// <param name="qos"></param> public void Send(short opcode, ISerializablePacket packet)/* OutgoingMessage msg)*/ { if (!IsConnected) { return; } using (PooledNetWriter w = NetWriterPool.GetWriter()) { MessageHelper.CreateAndFinalize(w, opcode, packet); var segment = w.ToArraySegment(); if (NetLogFilter.messageDiagnostics) { NetDiagnostics.OnSend(opcode, segment.Count, 1); } Send(segment); } }
public static void Recycle(PooledNetWriter writer) { pool.Push(writer); }