Example #1
0
        private void SendMessage(string message, Socket receiver)
        {
            FrameParser frameParser = new FrameParser();
            var         dataToSend  = frameParser.CreateFrameFromString(message);

            receiver.Send(dataToSend);
        }
Example #2
0
        private string ReceiveMessage(Client client)
        {
            IPAddress ip          = IPAddress.Parse(((IPEndPoint)client.GetClientSocket().RemoteEndPoint).Address.ToString());
            var       frameParser = new FrameParser();

            while (true)
            {
                var    receivedData = new byte[1000000];
                string receivedString;
                client.GetClientSocket().Receive(receivedData);
                if ((receivedData[0] & (byte)Opcode.CloseConnection) == (byte)Opcode.CloseConnection)
                {
                    Disconnect(client);
                    return("");
                }
                else
                {
                    receivedString = frameParser.ParsePayloadFromFrame(receivedData);
                    return(receivedString);
                }
            }
        }