public override void SendMessage(INetOutgoingMessage msg, MyNetDeliveryMethod method, int sequenceChannel) { byte[] message = new byte[msg.messageLength]; for (int i = 0; i < msg.messageLength; i++) { message[i] = msg.message[i]; } server.Send1(message); }
void DoSendPacket(INetOutgoingMessage msg) { byte[] packet = new byte[msg.messageLength + 4]; WriteInt(packet, 0, msg.messageLength); for (int i = 0; i < msg.messageLength; i++) { packet[i + 4] = msg.message[i]; } platform.TcpSend(packet, msg.messageLength + 4); }
// TODO: Use or remove method parameter public override void SendMessage(INetOutgoingMessage msg, MyNetDeliveryMethod method, int sequenceChannel) { try { ((EnetPeerNative)peer).peer.Send(0, msg.message, (ENet.PacketFlags)EnetPacketFlags.Reliable); } catch { } }
public void SendPacket(int client, Packet_Server packet) { IntRef length = new IntRef(); byte[] data = ServerPackets.Serialize(packet, length); INetOutgoingMessage msg = new INetOutgoingMessage(); msg.Write(data, length.value); clients[client].Connection.SendMessage(msg, MyNetDeliveryMethod.ReliableOrdered, 0); }
public override void SendMessage(INetOutgoingMessage message, MyNetDeliveryMethod method) { INetOutgoingMessage msg = message; if (!connected2) { tosend.Enqueue(msg); return; } DoSendPacket(msg); }
internal INetOutgoingMessage Dequeue() { INetOutgoingMessage ret = items[0]; for (int i = 0; i < count - 1; i++) { items[i] = items[i + 1]; } count--; return(ret); }
public override void SendMessage(INetOutgoingMessage msg, MyNetDeliveryMethod method, int sequenceChannel) { INetOutgoingMessage msg1 = (INetOutgoingMessage)msg; byte[] data = new byte[msg1.messageLength]; for (int i = 0; i < msg1.messageLength; i++) { data[i] = msg1.message[i]; } peer.Send(data); }
public override void SendMessage(INetOutgoingMessage message, MyNetDeliveryMethod method) { platform.MonitorEnter(network.ServerReceiveBufferLock); { INetOutgoingMessage msg = message; ByteArray b = new ByteArray(); b.data = msg.message; b.length = msg.messageLength; network.ServerReceiveBuffer.Enqueue(b); } platform.MonitorExit(network.ServerReceiveBufferLock); }
/// <summary> /// Approves this connection; sending a connection response to the remote host /// </summary> /// <param name="localHail">The local hail message that will be set as RemoteHailMessage on the remote host</param> public void Approve(INetOutgoingMessage localHail) { if (m_status != NetConnectionStatus.RespondedAwaitingApproval) { m_peer.LogWarning("Approve() called in wrong status; expected RespondedAwaitingApproval; got " + m_status); return; } m_localHailMessage = (NetOutgoingMessage)localHail; m_handshakeAttempts = 0; SendConnectResponse(NetTime.Now, false); }
/// <summary> /// Send a message to all connections /// </summary> /// <param name="msg">The message to send</param> /// <param name="method">How to deliver the message</param> public void SendToAll(INetOutgoingMessage msg, NetDeliveryMethod method) { NetOutgoingMessage _msg = (NetOutgoingMessage)msg; var all = this.Connections; if (all.Count <= 0) { if (_msg.m_isSent == false) Recycle(_msg); return; } SendMessage(msg, all, method, 0); }
public override void SendMessage(INetOutgoingMessage msg, MyNetDeliveryMethod method, int sequenceChannel) { platform.MonitorEnter(network.ClientReceiveBufferLock); { INetOutgoingMessage msg2 = msg; ByteArray b = new ByteArray(); b.data = msg2.message; b.length = msg2.messageLength; network.ClientReceiveBuffer.Enqueue(b); } platform.MonitorExit(network.ClientReceiveBufferLock); }
internal void Enqueue(INetOutgoingMessage p) { if (count == itemsSize) { INetOutgoingMessage[] items2 = new INetOutgoingMessage[itemsSize * 2]; for (int i = 0; i < itemsSize; i++) { items2[i] = items[i]; } itemsSize = itemsSize * 2; items = items2; } items[count++] = p; }
/// <summary> /// Send a message to a list of connections /// </summary> /// <param name="msg">The message to send</param> /// <param name="recipients">The list of recipients to send to</param> /// <param name="method">How to deliver the message</param> /// <param name="sequenceChannel">Sequence channel within the delivery method</param> public void SendMessage(INetOutgoingMessage msg, IList<INetConnection> recipients, NetDeliveryMethod method, int sequenceChannel) { NetOutgoingMessage _msg = (NetOutgoingMessage)msg; if (msg == null) throw new ArgumentNullException("msg"); if (recipients == null) { if (_msg.m_isSent == false) Recycle(_msg); throw new ArgumentNullException("recipients"); } if (recipients.Count < 1) { if (_msg.m_isSent == false) Recycle(_msg); throw new NetException("recipients must contain at least one item"); } if (method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.ReliableUnordered) NetException.Assert(sequenceChannel == 0, "Delivery method " + method + " cannot use sequence channels other than 0!"); if (_msg.m_isSent) throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently"); _msg.m_isSent = true; int mtu = GetMTU(recipients); int len = _msg.GetEncodedSize(); if (len <= mtu) { Interlocked.Add(ref _msg.m_recyclingCount, recipients.Count); foreach (NetConnection conn in recipients) { if (conn == null) { Interlocked.Decrement(ref _msg.m_recyclingCount); continue; } NetSendResult res = conn.EnqueueMessage(_msg, method, sequenceChannel); if (res == NetSendResult.Dropped) Interlocked.Decrement(ref _msg.m_recyclingCount); } } else { // message must be fragmented! SendFragmentedMessage(_msg, recipients, method, sequenceChannel); } return; }
public override NetIncomingMessage ReadMessage() { if (!connected) { return(null); } if (messages.Count() > 0) { return(messages.Dequeue()); } if (connected2) { while (tosend.Count() > 0) { INetOutgoingMessage msg = tosend.Dequeue(); DoSendPacket(msg); } } EnetEventRef event_ = new EnetEventRef(); if (platform.EnetHostService(host, 0, event_)) { do { switch (event_.e.Type()) { case EnetEventType.Connect: connected2 = true; break; case EnetEventType.Receive: byte[] data = event_.e.Packet().GetBytes(); int dataLength = event_.e.Packet().GetBytesCount(); event_.e.Packet().Dispose(); NetIncomingMessage msg = new NetIncomingMessage(); msg.message = data; msg.messageLength = dataLength; messages.Enqueue(msg); break; } }while (platform.EnetHostCheckEvents(host, event_)); } if (messages.Count() > 0) { return(messages.Dequeue()); } return(null); }
void SendRequest(NetClient client) { //Create request packet Packet_Client pp = ClientPackets.ServerQuery(); //Serialize packet CitoMemoryStream ms = new CitoMemoryStream(); Packet_ClientSerializer.Serialize(ms, pp); byte[] data = ms.ToArray(); //Send packet to server INetOutgoingMessage msg = new INetOutgoingMessage(); msg.Write(data, ms.Length()); client.SendMessage(msg, MyNetDeliveryMethod.ReliableOrdered); }
/// <summary> /// Send a discovery response message /// </summary> public void SendDiscoveryResponse(INetOutgoingMessage msg, NetEndPoint recipient) { NetOutgoingMessage _msg = (NetOutgoingMessage)msg; if (recipient == null) throw new ArgumentNullException("recipient"); if (msg == null) msg = CreateMessage(0); else if (_msg.m_isSent) throw new NetException("Message has already been sent!"); if (msg.LengthBytes >= m_configuration.MaximumTransmissionUnit) throw new NetException("Cannot send discovery message larger than MTU (currently " + m_configuration.MaximumTransmissionUnit + " bytes)"); _msg.m_messageType = NetMessageType.DiscoveryResponse; Interlocked.Increment(ref _msg.m_recyclingCount); m_unsentUnconnectedMessages.Enqueue(new NetTuple<NetEndPoint, NetOutgoingMessage>(recipient, _msg)); }
/// <summary> /// Send a message to a specific connection /// </summary> /// <param name="msg">The message to send</param> /// <param name="recipient">The recipient connection</param> /// <param name="method">How to deliver the message</param> /// <param name="sequenceChannel">Sequence channel within the delivery method</param> public NetSendResult SendMessage(INetOutgoingMessage msg, INetConnection recipient, NetDeliveryMethod method, int sequenceChannel) { NetOutgoingMessage _msg = (NetOutgoingMessage)msg; NetConnection _recipient = (NetConnection)recipient; if (msg == null) throw new ArgumentNullException("msg"); if (recipient == null) throw new ArgumentNullException("recipient"); if (sequenceChannel >= NetConstants.NetChannelsPerDeliveryMethod) throw new ArgumentOutOfRangeException("sequenceChannel"); NetException.Assert( ((method != NetDeliveryMethod.Unreliable && method != NetDeliveryMethod.ReliableUnordered) || ((method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.ReliableUnordered) && sequenceChannel == 0)), "Delivery method " + method + " cannot use sequence channels other than 0!" ); NetException.Assert(method != NetDeliveryMethod.Unknown, "Bad delivery method!"); if (_msg.m_isSent) throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently"); _msg.m_isSent = true; bool suppressFragmentation = (method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.UnreliableSequenced) && m_configuration.UnreliableSizeBehaviour != NetUnreliableSizeBehaviour.NormalFragmentation; int len = NetConstants.UnfragmentedMessageHeaderSize + msg.LengthBytes; // headers + length, faster than calling msg.GetEncodedSize if (len <= _recipient.m_currentMTU || suppressFragmentation) { Interlocked.Increment(ref _msg.m_recyclingCount); return _recipient.EnqueueMessage(_msg, method, sequenceChannel); } else { // message must be fragmented! if (_recipient.m_status != NetConnectionStatus.Connected) return NetSendResult.FailedNotConnected; return SendFragmentedMessage(_msg, new NetConnection[] { _recipient }, method, sequenceChannel); } }
public override NetIncomingMessage ReadMessage() { if (connected.value) { while (tosend.Count() > 0) { INetOutgoingMessage msg = tosend.Dequeue(); DoSendPacket(msg); } } NetIncomingMessage message = GetMessage(); if (message != null) { return(message); } for (int k = 0; k < 1; k++) { int received = platform.TcpReceive(data, dataLength); if (received <= 0) { break; } for (int i = 0; i < received; i++) { incoming.Enqueue(data[i]); } } message = GetMessage(); if (message != null) { return(message); } return(null); }
void DoSendPacket(INetOutgoingMessage msg) { INetOutgoingMessage msg1 = msg; platform.EnetPeerSend(peer, 0, msg1.message, msg1.messageLength, EnetPacketFlags.Reliable); }
public NetSendResult SendMessage(INetOutgoingMessage msg, NetDeliveryMethod method) { return NetSendResult.Sent; }
/// <summary> /// Send a message to this exact same netpeer (loopback) /// </summary> public void SendUnconnectedToSelf(INetOutgoingMessage om) { NetOutgoingMessage _om = (NetOutgoingMessage)om; if (om == null) throw new ArgumentNullException("msg"); if (_om.m_isSent) throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently"); _om.m_messageType = NetMessageType.Unconnected; _om.m_isSent = true; if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == false) { Interlocked.Decrement(ref _om.m_recyclingCount); return; // dropping unconnected message since it's not enabled for receiving } // convert outgoing to incoming NetIncomingMessage im = CreateIncomingMessage(NetIncomingMessageType.UnconnectedData, om.LengthBytes); im.Write(om); im.m_isFragment = false; im.m_receiveTime = NetTime.Now; im.m_senderConnection = null; im.m_senderEndPoint = m_socket.LocalEndPoint as NetEndPoint; NetException.Assert(im.m_bitLength == om.LengthBits); // recycle outgoing message Recycle(_om); ReleaseMessage(im); }
/// <summary> /// Create a connection to a remote endpoint /// </summary> public virtual INetConnection Connect(NetEndPoint remoteEndPoint, INetOutgoingMessage hailMessage) { if (remoteEndPoint == null) throw new ArgumentNullException("remoteEndPoint"); lock (m_connections) { if (m_status == NetPeerStatus.NotRunning) throw new NetException("Must call Start() first"); if (m_connectionLookup.ContainsKey(remoteEndPoint)) throw new NetException("Already connected to that endpoint!"); NetConnection hs; if (m_handshakes.TryGetValue(remoteEndPoint, out hs)) { // already trying to connect to that endpoint; make another try switch (hs.m_status) { case NetConnectionStatus.InitiatedConnect: // send another connect hs.m_connectRequested = true; break; case NetConnectionStatus.RespondedConnect: // send another response hs.SendConnectResponse(NetTime.Now, false); break; default: // weird LogWarning("Weird situation; Connect() already in progress to remote endpoint; but hs status is " + hs.m_status); break; } return hs; } NetConnection conn = new NetConnection(this, remoteEndPoint); conn.m_status = NetConnectionStatus.InitiatedConnect; conn.m_localHailMessage = (NetOutgoingMessage)hailMessage; // handle on network thread conn.m_connectRequested = true; conn.m_connectionInitiator = true; m_handshakes.Add(remoteEndPoint, conn); return conn; } }
/// <summary> /// Send a message to an unconnected host /// </summary> public void SendUnconnectedMessage(INetOutgoingMessage msg, string host, int port) { NetOutgoingMessage _msg = (NetOutgoingMessage)msg; if (msg == null) throw new ArgumentNullException("msg"); if (host == null) throw new ArgumentNullException("host"); if (_msg.m_isSent) throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently"); if (msg.LengthBytes > m_configuration.MaximumTransmissionUnit) throw new NetException("Unconnected messages too long! Must be shorter than NetConfiguration.MaximumTransmissionUnit (currently " + m_configuration.MaximumTransmissionUnit + ")"); _msg.m_isSent = true; _msg.m_messageType = NetMessageType.Unconnected; var adr = NetUtility.Resolve(host); if (adr == null) throw new NetException("Failed to resolve " + host); Interlocked.Increment(ref _msg.m_recyclingCount); m_unsentUnconnectedMessages.Enqueue(new NetTuple<NetEndPoint, NetOutgoingMessage>(new NetEndPoint(adr, port), _msg)); }
public void SendUnconnectedMessage(INetOutgoingMessage msg, IList<IPEndPoint> recipients) { }
public void SendUnconnectedMessage(INetOutgoingMessage msg, string host, int port) { throw new NotImplementedException(); }
public void SendMessage(INetOutgoingMessage msg, IList<INetConnection> recipients, NetDeliveryMethod method, int sequenceChannel) { }
public QueueINetOutgoingMessage() { items = new INetOutgoingMessage[1]; itemsSize = 1; count = 0; }
public void SendPacket(byte[] packet, int packetLength) { //try //{ INetOutgoingMessage msg = new INetOutgoingMessage(); msg.Write(packet, packetLength); main.SendMessage(msg, MyNetDeliveryMethod.ReliableOrdered); //} //catch //{ // game.p.ConsoleWriteLine("SendPacket error"); //} }
/// <summary> /// Create a connection to a remote endpoint /// </summary> public INetConnection Connect(string host, int port, INetOutgoingMessage hailMessage) { return Connect(GetNetEndPoint(host, port), hailMessage); }
public NetSendResult SendMessage(INetOutgoingMessage msg, INetConnection recipient, NetDeliveryMethod method, int sequenceChannel) { return NetSendResult.Sent; }
public override void SendMessage(INetOutgoingMessage msg, MyNetDeliveryMethod method, int sequenceChannel) { INetOutgoingMessage msg1 = msg; platform.EnetPeerSend(peer, 0, msg1.message, msg1.messageLength, EnetPacketFlags.Reliable); }
public void SendUnconnectedMessage(INetOutgoingMessage msg, IPEndPoint recipient) { throw new NotImplementedException(); }
public override void SendMessage(INetOutgoingMessage message, MyNetDeliveryMethod method) { c.SendMessage(message, method, 0); }
public void SendUnconnectedToSelf(INetOutgoingMessage om) { throw new NotImplementedException(); }
public abstract void SendMessage(INetOutgoingMessage msg, MyNetDeliveryMethod method, int sequenceChannel);
public abstract void SendMessage(INetOutgoingMessage message, MyNetDeliveryMethod method);
/// <summary> /// Send a message to an unconnected host /// </summary> public void SendUnconnectedMessage(INetOutgoingMessage msg, IList<NetEndPoint> recipients) { NetOutgoingMessage _msg = (NetOutgoingMessage)msg; if (msg == null) throw new ArgumentNullException("msg"); if (recipients == null) throw new ArgumentNullException("recipients"); if (recipients.Count < 1) throw new NetException("recipients must contain at least one item"); if (_msg.m_isSent) throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently"); if (msg.LengthBytes > m_configuration.MaximumTransmissionUnit) throw new NetException("Unconnected messages too long! Must be shorter than NetConfiguration.MaximumTransmissionUnit (currently " + m_configuration.MaximumTransmissionUnit + ")"); _msg.m_messageType = NetMessageType.Unconnected; _msg.m_isSent = true; Interlocked.Add(ref _msg.m_recyclingCount, recipients.Count); foreach (NetEndPoint ep in recipients) m_unsentUnconnectedMessages.Enqueue(new NetTuple<NetEndPoint, NetOutgoingMessage>(ep, _msg)); }
public INetConnection Connect(IPEndPoint remoteEndPoint, INetOutgoingMessage hailMessage) { return new FakeNetConnection(); }
/// <summary> /// Send a message to a specific connection /// </summary> /// <param name="msg">The message to send</param> /// <param name="recipient">The recipient connection</param> /// <param name="method">How to deliver the message</param> public NetSendResult SendMessage(INetOutgoingMessage msg, INetConnection recipient, NetDeliveryMethod method) { return SendMessage(msg, recipient, method, 0); }
public INetConnection Connect(string host, int port, INetOutgoingMessage hailMessage) { return new FakeNetConnection(); }
public void SendDiscoveryResponse(INetOutgoingMessage msg, IPEndPoint recipient) { throw new NotImplementedException(); }
public override void SendMessage(INetOutgoingMessage msg, MyNetDeliveryMethod method, int sequenceChannel) { platform.WebSocketSend(msg.message, msg.messageLength); }