コード例 #1
0
ファイル: Server.cs プロジェクト: Stroby241/GrappleGame
    /// <summary>Starts the server.</summary>
    /// <param name="maxPlayers">The maximum players that can be connected simultaneously.</param>
    /// <param name="port">The port to start the server on.</param>
    public static void Start(int maxPlayers, int port)
    {
        ip = IPManager.GetIPAddress();

        Debug.Log(ip);

        MaxPlayers = maxPlayers;
        Port       = port;

        Debug.Log("Starting server...");
        InitializeServerData();

        tcpListener = new TcpListener(IPAddress.Any, Port);
        tcpListener.Start();
        tcpListener.BeginAcceptTcpClient(TcpConnectCallback, null);

        udpListener = new UdpClient(Port);
        udpListener.BeginReceive(UdpReceiveCallback, null);

        Debug.Log($"Server started on port {Port}.");
    }