Exemplo n.º 1
0
    void OnGUI()
    {
        ServerIP = GUI.TextField(new Rect(0, 25, 240, 20), ServerIP, 25);

        // server
        GUI.enabled = !client.Connected;


        if (GUI.Button(new Rect(0, 50, 120, 20), "Join localhost"))
        {
            client.Connect(ServerIP, 1337);
        }

        GUI.enabled = client.Connected;
        if (GUI.Button(new Rect(130, 50, 120, 20), "Disconnect"))
        {
            client.Disconnect();
            for (int i = 0; i < Players.Count; i++)
            {
                Destroy(Players[i].PlayerOBJ);
            }
            Players.Clear();
        }

        GUI.enabled = true;
    }
Exemplo n.º 2
0
    void OnGUI()
    {
        // client
        GUI.enabled = !client.Connected;
        if (GUI.Button(new Rect(0, 0, 120, 20), "Connect Client"))
        {
            client.Connect("localhost", 1337);
        }

        GUI.enabled = client.Connected;
        if (GUI.Button(new Rect(130, 0, 120, 20), "Disconnect Client"))
        {
            client.Disconnect();
        }

        // server
        GUI.enabled = !server.Active;
        if (GUI.Button(new Rect(0, 25, 120, 20), "Start Server"))
        {
            server.Start(1337);
        }

        GUI.enabled = server.Active;
        if (GUI.Button(new Rect(130, 25, 120, 20), "Stop Server"))
        {
            server.Stop();
        }

        GUI.enabled = true;
    }
Exemplo n.º 3
0
    void OnGUI()
    {
        // client
        GUI.enabled = !client.Connected;
        if (GUI.Button(new Rect(0, 0, 120, 20), "Connect Client"))
        {
            client.Connect("localhost", 1337);
            GameObject.Instantiate(PlayerPrefab, Vector3.zero, Quaternion.identity);
        }

        GUI.enabled = client.Connected;
        if (GUI.Button(new Rect(130, 0, 120, 20), "Disconnect Client"))
        {
            client.Disconnect();
        }

        // server
        GUI.enabled = !server.Active;
        if (GUI.Button(new Rect(0, 25, 120, 20), "Start Server"))
        {
            server.Start(1337);
        }

        GUI.enabled = server.Active;
        if (GUI.Button(new Rect(130, 25, 120, 20), "Stop Server"))
        {
            server.Stop();
        }

        GUI.enabled = true;
    }
 void OnApplicationQuit()
 {
     // the client/server threads won't receive the OnQuit info if we are
     // running them in the Editor. they would only quit when we press Play
     // again later. this is fine, but let's shut them down here for consistency
     _client.Disconnect();
 }
Exemplo n.º 5
0
    static void Main(string[] args)
    {
        client = new Telepathy.Client();
        client.Connect("localhost", 1337);

        Task.Run(() =>
        {
            while (client.Connected)
            {
                Telepathy.Message msg;
                while (client.GetNextMessage(out msg))
                {
                    // clientの場合、msg.connectionIdは常に0が格納されている
                    switch (msg.eventType)
                    {
                    case Telepathy.EventType.Connected:
                        Console.WriteLine("Telepathy.EventType.Connected : msg.connectionId=" + msg.connectionId);
                        break;

                    case Telepathy.EventType.Data:
                        Console.WriteLine("Telepathy.EventType.Data : msg.connectionId=" + msg.connectionId + ", msg.data" + System.Text.Encoding.UTF8.GetString(msg.data));
                        break;

                    case Telepathy.EventType.Disconnected:
                        Console.WriteLine("Telepathy.EventType.Disconnected : msg.connectionId=" + msg.connectionId);
                        break;
                    }
                }
            }
        });

        bool break_flag = false;

        while (break_flag == false)
        {
            ConsoleKey k = Console.ReadKey().Key;
            switch (k)
            {
            case ConsoleKey.Spacebar:
                Console.WriteLine("send massage from client...");
                client.Send(System.Text.Encoding.UTF8.GetBytes("send message from server..."));
                break;

            case ConsoleKey.Escape:
                break_flag = true;
                break;
            }
        }

        client.Disconnect();
    }
Exemplo n.º 6
0
 public override void ClientDisconnect() => client.Disconnect();
Exemplo n.º 7
0
 public void Disconnect()
 {
     _client.Disconnect();
 }