public MainPage() { this.InitializeComponent(); float lastUpdate = 12.481f; HostInformation hostInformation = new HostInformation(lastUpdate.GetHashCode().ToString(), NetworkComponents.GetLocalIPv4(), "Your name", lastUpdate, true); byte[] byteArray = HostInformation.Serialize(hostInformation); HostInformation deserialized = HostInformation.Deserialize(byteArray); receiver = new NetworkComponents.UDPReceiver(this.MessageReceived); //this.broadcaster = new NetworkComponents.UDPBroadcaster(); //this.broadcaster.Broadcast(hostInformation); }
// Serialize HostInformation public static byte[] Serialize(HostInformation message) { MemoryStream ms = new MemoryStream(); CustomSerializer.SerializeString(ms, "IGridforceMessage"); CustomSerializer.SerializeString(ms, "HostInformation"); CustomSerializer.SerializeString(ms, message.instanceID); CustomSerializer.SerializeString(ms, message.hostIP); CustomSerializer.SerializeString(ms, message.hostName); CustomSerializer.SerializeDouble(ms, (double)(message.lastUpdate)); CustomSerializer.SerializeBool(ms, message.passwordProtected); return ms.ToArray(); }
static void Main(string[] args) { // UDP testing HostInformation hostInformation = new HostInformation("DE98F9", "127.0.0.1", "Markus", 0.0f, true); byte[] byteArray = HostInformation.Serialize(hostInformation); HostInformation deserialized = HostInformation.Deserialize(byteArray); NetworkComponents.UDPBroadcaster broadcaster = new NetworkComponents.UDPBroadcaster(); NetworkComponents.UDPReceiver receiver = new NetworkComponents.UDPReceiver(null); broadcaster.Broadcast(hostInformation); // TCP testing //NetworkComponents.TCPConnector hostConnector = new NetworkComponents.TCPConnector(OnMesageReceivedFromClient, true); //while (!(hostConnector.Listen())) //{ //} //hostConnector.Send(hostInformation); //hostConnector.Close(); UserInformation user = new UserInformation("Markus", "127.0.0.1"); byte[] data = UserInformation.Serialize(user); user = UserInformation.Deserialize(data); JoinRequest request = new JoinRequest(user, PasswordFunctions.HashPassword("penis1337")); data = JoinRequest.Serialize(request); request = JoinRequest.Deserialize(data); NetworkComponents.TCPConnector hostConnector = new NetworkComponents.TCPConnector(OnMesageReceivedFromClient, false); while (!(hostConnector.AcceptConnection("127.0.0.1"))) { } hostConnector.Send(hostInformation); hostConnector.Close(); }