private void HandshakeStepTwo(BaseConnectionEntity con) { ByteStreamWriter writer = new ByteStreamWriter(); writer.WriteByte((byte)MsgFlags.ConnectionRequest); writer.WriteByte((byte)HandshakeMessage.SYNACK); writer.WriteInteger(con.m_connectionId); con.m_sender.Send(writer.GetBytes()); con.m_sender.Send(writer.GetBytes()); con.m_sender.Send(writer.GetBytes()); con.m_sender.Send(writer.GetBytes()); }
/// <summary> /// Sends an event to a client. /// </summary> /// <param name="e">Event to send.</param> /// <param name="connectionId">Target client's connection id</param> /// <param name="reliable">Is it reliable event</param> /// <param name="internalResend">If <c>false</c> this event will be added to reliable events queue as a new event</param> /// <returns><c>true</c> if the target client is connected</returns> public bool Send(EventBase e, int connectionId, bool reliable = false, bool internalResend = false) { ByteStreamWriter stream = new ByteStreamWriter(); stream.WriteByte(reliable ? ( byte )MsgFlags.ReliableEvent : ( byte )MsgFlags.UnreliableEvent); stream.WriteByte(e.GetId()); e.Serialize(stream); Connection c = m_server.GetConnectionById(connectionId); if (c != null) { c.Send(stream.GetBytes()); if (reliable && !internalResend && e is ReliableEventBase) { ReliableEventBase reb = e as ReliableEventBase; m_reliablesToRepeat[reb.m_reliableEventId] = new REventIdPair(connectionId, reb); } return(true); } else { return(false); } }
/// <summary> /// Starts handshake process. /// </summary> /// <param name="receivePort">The port server should send data to.</param> public void HandshakeStepOne(int receivePort) { ByteStreamWriter writer = new ByteStreamWriter(); writer.WriteByte((byte)MsgFlags.ConnectionRequest); writer.WriteByte((byte)HandshakeMessage.SYN); writer.WriteInteger(receivePort); m_sender.Send(writer.GetBytes()); State = ConnectionState.Connecting; }
/// <summary> /// Sends an event to a server. /// </summary> /// <param name="e">Event to send.</param> /// <param name="reliable">Is it reliable event</param> /// <param name="internalResend">If <c>false</c> this event will be added to reliable events queue as a new event</param> /// <returns><c>true</c> if the target client is connected</returns> public void Send(EventBase e, bool reliable = false, bool internalResend = false) { ByteStreamWriter stream = new ByteStreamWriter(); stream.WriteByte(reliable ? (byte)MsgFlags.ReliableEvent : (byte)MsgFlags.UnreliableEvent); stream.WriteByte(e.GetId()); e.Serialize(stream); m_client.Send(stream.GetBytes()); if (reliable && !internalResend && e is ReliableEventBase) { ReliableEventBase reb = e as ReliableEventBase; m_reliablesToRepeat[reb.m_reliableEventId] = reb; } }
/// <summary> /// Sends a confirmation of receiving the Connection ID to server (finalizes the connection on the Client side) /// </summary> /// <param name="connectionId">The connection identifier.</param> public void HandshakeStepThree(int connectionId) { ByteStreamWriter writer = new ByteStreamWriter(); writer.WriteByte((byte)MsgFlags.ConnectionRequest); writer.WriteByte((byte)HandshakeMessage.ACK); writer.WriteInteger(connectionId); for (int i = 0; i < 5; ++i) { m_sender.Send(writer.GetBytes()); } ConnectionId = connectionId; State = ConnectionState.Connected; Network.Log(State + ", " + ConnectionId); }
public ByteStreamReader(ByteStreamWriter writer) : this(writer.GetBytes()) { }
/// <summary> /// Sends raw bytestream to server /// </summary> /// <param name="stream">The stream.</param> public void Send(ByteStreamWriter stream) { m_client.Send(stream.GetBytes()); }