Networking.Client.Send C# (CSharp) Method

Send() public method

Sends a bunch of data to the server
public Send ( byte data ) : void
data byte The data to send
return void
        public void Send(byte[] data)
        {
            if (_socket == null)
                return;
            if (data == null)
                return;

            while (_receiving) {
                Thread.Sleep(200);
            }

            try {
                _socket.Send(data);
            } catch (Exception e) {
                Disconnect();
            }
        }

Usage Example

Beispiel #1
0
        static void Main(string[] args)
        {
            IPEndPoint local = new IPEndPoint(IPAddress.Any,0);
            IPEndPoint remote = new IPEndPoint(IPAddress.Parse("192.168.89.53"), 40004);

            Client client = new Client(local, remote);

            client.Send(new NetworkMessage("aaaaaaaaaaaa").GetBytesForTransfer());
            Console.Out.WriteLine("Sent1");
            client.Send(new NetworkMessage("bbbbbbbbbbbb").GetBytesForTransfer());
            Console.Out.WriteLine("Sent2");
            client.Send(new NetworkMessage("cccccccccccc").GetBytesForTransfer());
            Console.Out.WriteLine("Sent3");

            Console.ReadKey();
        }