Ejemplo n.º 1
0
    void sendDiscoveryPing()
    {
        Debug.Log("[SERVER] sending discovery ping");
        DiscoveryPingMessage dpm = new DiscoveryPingMessage(NetworkService.GetSelfIP());

        dpm.setMessageHeaders(NetworkService.GetSelfIP());
        string message = dpm.encodeMessage();

        Byte[] bytes = Encoding.ASCII.GetBytes(message);
        broadcaster.Send(bytes, bytes.Length, broadcastEndPoint);
    }
Ejemplo n.º 2
0
    void parseConnectionSearchMessage(string message)
    {
        try {
            NetworkMessage networkMessage = NetworkMessage.decodeMessage(message);
            string         messageType    = networkMessage.thisMessageType();
            Debug.Log("[CLIENT] got connection ping from server. " + message);
            if (messageType == typeof(DiscoveryPingMessage).FullName)
            {
                DiscoveryPingMessage dpm = (DiscoveryPingMessage)networkMessage;
                this.node       = new NetworkNode(dpm.sourceIp.ToString(), Config.serverListenPort);
                this.serverNode = new NetworkNode(dpm.sourceIp.ToString(), Config.clientListenPort);
                startListening(this.serverNode);

                // send initial connection message
                ipAddress = NetworkService.GetSelfIP();
                PlayerUpdateMessage joinMsg = new PlayerUpdateMessage(ipAddress, "join");
                this.sendMessageToServer(joinMsg);
                serverDiscoveryClient.Close();
            }
        } catch (Exception e) {
            Debug.Log(whoAmI() + e);
        }
    }