예제 #1
0
            // Broadcast a message via UDP
            public void Broadcast(IGridforceMessage message)
            {
                byte[] data = QuickSerializer.Serialize(message);

                this.udpClient.Send(data, data.Length, this.remoteEndPoint);
            }
예제 #2
0
 // Receive message from TCP connection
 private void Receive(TCPConnection connection, IGridforceMessage message)
 {
     if (this.OnMessageReceived != null)
         this.OnMessageReceived(connection, message);
 }
예제 #3
0
            // Send message to all TCP connections
            public void Send(IGridforceMessage message)
            {
                for (int i = 0; i < this.connectionList.Count; i++)
                {
                    if (this.connectionList[i].closed)
                    {

                        this.connectionList.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                        this.connectionList[i].Send(message);
                    }
                }
            }
예제 #4
0
            // Send message to TCP connection
            public void Send(IGridforceMessage message)
            {
                byte[] data = QuickSerializer.Serialize(message);
                byte[] size = BitConverter.GetBytes(data.Length);
                if (!(BitConverter.IsLittleEndian))
                    Array.Reverse(size);

                try
                {
                    this.stream.Write(size, 0, 4);
                    this.stream.Write(data, 0, data.Length);
                }
                catch (Exception)
                {
                }
            }
예제 #5
0
            async private Task BroadcastAsync(IGridforceMessage message)
            {
                if (this.sender == null)
                    return;

                byte[] data = QuickSerializer.Serialize(message);

                IOutputStream outputStream = await this.sender.GetOutputStreamAsync(new HostName(NetworkComponents.multicastIP), NetworkComponents.gamePort.ToString());

                try
                {
                    await outputStream.WriteAsync(data.AsBuffer());
                    await outputStream.FlushAsync();
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
예제 #6
0
 // Broadcast a message via UDP
 public void Broadcast(IGridforceMessage message)
 {
     Task task = Task.Run(async () => { await this.BroadcastAsync(message); });
     task.Wait();
 }