public void SendGoodbye() { var user = MasterContainer.GetService <User>(); var goodbye = new GoodbyeRequest(user); var requestData = EncryptRequest(goodbye, SessionCrypter); client.Send(requestData); }
protected override LineProtocolWriteResult OnSend( string payload, Precision precision, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(payload)) { return(new LineProtocolWriteResult(true, null)); } var buffer = Encoding.UTF8.GetBytes(payload); _tcpSender.Send(buffer); return(new LineProtocolWriteResult(true, null)); }
public void SendMessageToServer(byte[] messageData) { byte[] dataToSend; if (_useOctetCounting) { var prefix = Encoding.UTF8.GetBytes($"{messageData.Length} "); dataToSend = new byte[prefix.Length + messageData.Length]; Array.Copy(prefix, 0, dataToSend, 0, prefix.Length); Array.Copy(messageData, 0, dataToSend, prefix.Length, messageData.Length); } else { dataToSend = messageData; } _tcpSender.Send(dataToSend); }
private void OnConnected(TcpSender sender) { AppendMessage(sender.RemoteEndPoint.ToString(), sender.RemoteEndPoint.ToString() + " join.", MessageType.Join); clientNumber = server.Clients.Count; SetOnlineNumber(clientNumber); byte[] tmp = sender.Guid.ToByteArray(); byte[] buffer = new byte[tmp.Length + 7]; buffer[0] = 0x02; buffer[buffer.Length - 6] = 0x4F; buffer[buffer.Length - 5] = (byte)(clientNumber & 0xff); buffer[buffer.Length - 4] = (byte)((clientNumber >> 8) & 0xff); buffer[buffer.Length - 3] = (byte)((clientNumber >> 16) & 0xff); buffer[buffer.Length - 2] = (byte)((clientNumber >> 24) & 0xff); buffer[buffer.Length - 1] = 0x03; Buffer.BlockCopy(tmp, 0, buffer, 1, tmp.Length); sender.Send(buffer); Send(sender, buffer); }