// Broadcast a message via UDP public void Broadcast(IGridforceMessage message) { byte[] data = QuickSerializer.Serialize(message); this.udpClient.Send(data, data.Length, this.remoteEndPoint); }
// Receive message from TCP connection private void Receive(TCPConnection connection, IGridforceMessage message) { if (this.OnMessageReceived != null) this.OnMessageReceived(connection, message); }
// 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); } } }
// 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) { } }
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; } }
// Broadcast a message via UDP public void Broadcast(IGridforceMessage message) { Task task = Task.Run(async () => { await this.BroadcastAsync(message); }); task.Wait(); }