Пример #1
0
    private void EstablishConnection(Connection con)
    {
        // Send my name...
        con.SendMessage(Name);

        // Wait for a message...
        SplashKit.CheckNetworkActivity();
        for (int i = 0; i < 10 && !con.HasMessages; i++)
        {
            SplashKit.CheckNetworkActivity();
        }

        if (!con.HasMessages)
        {
            con.Close();
            throw new Exception("Timeout waiting for name of peer");
        }

        // Read the name
        string name = con.ReadMessageData();

        // See if we can register this...
        if (_peers.ContainsKey(name))
        {
            con.Close();
            throw new Exception("Unable to connect to multiple peers with the same name");
        }

        // Register
        _peers[name] = con;
        Console.WriteLine($"Connected to {name} at { SplashKit.Ipv4ToStr(con.IP) }:{con.Port}");
    }
Пример #2
0
    public string GetNewMessages()
    {
        SplashKit.CheckNetworkActivity();

        while (SplashKit.HasMessages())
        {
            using (Message m = SplashKit.ReadMessage())
            {
                GetMsg = m.Data;
            }
        }
        return(GetMsg);
    }
Пример #3
0
    public void PrintNewMessages()
    {
        SplashKit.CheckNetworkActivity();

        while (SplashKit.HasMessages())
        {
            using (Message m = SplashKit.ReadMessage())
            {
                Console.WriteLine($"Got message from {m.Host}:{m.Port}");
                Console.WriteLine(m.Data);
            }
        }
    }
Пример #4
0
    public string GetNewMessages()
    {
        SplashKit.CheckNetworkActivity();

        while (SplashKit.HasMessages())
        {
            using (Message m = SplashKit.ReadMessage())
            {
                //Console.WriteLine($"Got message from {m.Host}:{m.Port}");
                GetMsg = m.Data;
            }
        }
        return(GetMsg);
    }