Exemplo n.º 1
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.º 2
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;
    }
Exemplo n.º 3
0
    static void Main(string[] args)
    {
        server = new Telepathy.Server();
        server.Start(1337);

        Task.Run(() =>
        {
            while (server.Active)
            {
                Telepathy.Message msg;
                while (server.GetNextMessage(out msg))
                {
                    switch (msg.eventType)
                    {
                    case Telepathy.EventType.Connected:
                        // msg.connectionIdはクライアント接続時に+1される数値。1始まり
                        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));

                        // reply
                        Console.WriteLine("send massage from server...");
                        server.Send(msg.connectionId, System.Text.Encoding.UTF8.GetBytes("send message from server..."));
                        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.L:
                break;

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

        server.Stop();
    }
Exemplo n.º 4
0
 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
     if (client != null)
     {
         client.Disconnect();
     }
     if (server != null)
     {
         server.Stop();
     }
 }
Exemplo n.º 5
0
 public void Stop()
 {
     _server.Stop();
 }
Exemplo n.º 6
0
 public override void ServerStop() => server.Stop();
 void OnApplicationQuit()
 {
     Debug.Log("BADNetworkServer.OnApplicationQuit");
     _server.Stop();
 }
Exemplo n.º 8
0
 void Stop()
 {
     server.Stop();
     OnServerStopped();
 }
Exemplo n.º 9
0
 void OnApplicationQuit()
 {
     server.Stop();
 }