Пример #1
0
    public static void WaitForConnection(string host)
    {
        tc = new TcpClient();
        tc.Client.NoDelay = true;
        tc.Connect(host, 12345);
        ns               = tc.GetStream();
        hasClientID      = false;
        forcedDisconnect = false;
        try
        {
            LongEventHandler.QueueLongEvent(() =>
            {
                PirateRPC.PirateRPC.SendInvocation(ns, u =>
                {
                    int cid = SyncTickData.cliendID;
                    Interlocked.Increment(ref SyncTickData.cliendID);
                    NetDemo.ServerHandlePlayerJoined(cid, u);
                });

                for (; !hasClientID && !forcedDisconnect;)
                {
                }
            }, "Waiting for server".Translate(), true, e => { RimLog.Error(e.ToString()); });
        }
        catch (Exception ee)
        {
            log(ee.ToString());
        }

        Thread t = new Thread(() =>
        {
            for (;  ;)
            {
                PirateRPC.PirateRPC.ReceiveInvocation(ns);
            }
        });

        t.Start();
    }