Example #1
0
        static void SendData(Socket connection, string message)
        {
            try
            {
                Mesaj send = new Mesaj();
                send.Id = 10;
                send.Name = message;

                byte[] data = Encoding.UTF8.GetBytes(message);
                data = send.Serialize();
                // We store how much data the server should expect
                // in the first 4 bytes of the data we're going to send
                byte[] head = BitConverter.GetBytes(data.Length);

                byte[] total = new byte[data.Length + head.Length];
                head.CopyTo(total, 0);
                data.CopyTo(total, head.Length);

                connection.BeginSend(total, 0, total.Length, 0, new AsyncCallback(SendCallBack), connection);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.Message);
            }
        }