예제 #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;
    }
예제 #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;
    }
예제 #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();
    }
예제 #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();
     }
 }
예제 #5
0
 public void Stop()
 {
     _server.Stop();
 }
예제 #6
0
 public override void ServerStop() => server.Stop();
 void OnApplicationQuit()
 {
     Debug.Log("BADNetworkServer.OnApplicationQuit");
     _server.Stop();
 }
예제 #8
0
 void Stop()
 {
     server.Stop();
     OnServerStopped();
 }
예제 #9
0
파일: Host.cs 프로젝트: dupperT/TCP_Network
 void OnApplicationQuit()
 {
     server.Stop();
 }