public CommunicationHandler(IInvokable invokable, IRequestable requestable) {
            _client = new UdpClient(Properties.Settings.Default.DefaultPort);
            _client.DataReceived += UdpClient_DataReceived;
            _client.Start();
            Console.WriteLine($"Started listening on udp port: {Properties.Settings.Default.DefaultPort}");

            _processor = new DataProcessor(_client, invokable, requestable);

        }
Beispiel #2
0
    // TODO: change this to an independent variable.

    // called so that the server is initialized as early as possible.
    // this wasn't initialized in time during testing due to initialization order.
    private void Awake()
    {
        // creates client if it's not set.
        if (client == null)
        {
            client = new NetworkLibrary.UdpClient();

            // two-way communication
            client.SetCommunicationMode(NetworkLibrary.UdpClient.mode.both);
        }
    }
        public CommunicationHandler(int port, IPlayerContainer container, INotifiable notify, IRequestable request) { // TODO: Interface ILobby

            _playerContainer = container;
            _tcpListener = new TcpListener(port);
            _tcpListener.SocketAccepted += SocketAccepted;
            _tcpListener.Start();

            _udpClient = new UdpClient(port);
            _udpClient.DataReceived += UdpClient_DataReceived;
            _udpClient.Start();

            _processor = new DataProcessor(notify, request);
            Console.WriteLine("Server started listening on port : {0}", ((IPEndPoint)_tcpListener.Socket.LocalEndPoint).Port);
        }
    public void JoinLobby(InputField input) {
        if (string.IsNullOrEmpty(input.text)) {
            input.text = "";
            GameObject.Find("JoinLobbyOverlay").SetActive(false);
            return;
        }

        UdpClient client = new UdpClient();
        client.Connect(new IPEndPoint(IPAddress.Parse(GlobalSettings.Instance.ServerIp), GlobalSettings.Instance.ServerPort));
        string response = GetResponse(client.Socket, string.Format("Request:JoinLobby:{0}", input.text));
        if (response == null) {
            EndSession();
            return;
        }
        SetNameHandshake(response);
    }
    public void CreateLobby() {
        if (!GlobalSettings.LatestVersion) {
            ShowError("Failed to retrieve the server settings.\n" +
                "Make sure you have a working internet connection.");
            return;
        }

        if (!LoginStatus())
            return;

        UdpClient client = new UdpClient();
        client.Connect(new IPEndPoint(IPAddress.Parse(GlobalSettings.Instance.ServerIp),
            GlobalSettings.Instance.ServerPort));

        string response = GetResponse(client.Socket, "Request:CreateLobby");
        if (response == null) {
            EndSession();
            return;
        }
        SetNameHandshake(response);
    }
 internal DataProcessor(UdpClient client, IInvokable invoke, IRequestable request) {
     _invoke = new Invoke(client, invoke);
     _request = new Request(client, request);
 }
 internal Invoke(UdpClient client, IInvokable invoke) {
     _client = client;
     _invoke = invoke;
 }
 internal Request(UdpClient client, IRequestable request) {
     _client = client;
     _request = request;
 }