public override void _Ready()
    {
        InputField  = (TextEdit)GetNode("Columns/IO Column/Input Field/TextEdit");
        OutputField = (TextEdit)GetNode("Columns/IO Column/Output Field/TextEdit");
        PeerList    = (VBoxContainer)GetNode("Columns/Information Column/PeerList Panel/Scroll Container/PeerList");
        IDLabel     = (Label)GetNode("Columns/Information Column/ID Panel/ID Data/ID String");

        networking = Networking.Instance;
        networking.Connect(nameof(Networking.ConnectedToSession), this, nameof(OnMeshJoined));
        networking.Connect(nameof(Networking.PeerAdded), this, nameof(OnPeerAdded));
    }
Пример #2
0
    /// <summary>
    /// Teleport to the given room with a scene name, ip address and port.
    /// </summary>
    /// <param name="scene">Scene to load</param>
    /// <param name="host">IP address of the host</param>
    /// <param name="port">Port of the host</param>
    public static void TeleportToRoom(string scene, string host, ushort port)
    {
        Application.LoadLevel(scene);

        Networking.Disconnect();
        Networking.Connect(host, port, Networking.TransportationProtocolType.TCP);
    }
Пример #3
0
    public void StartClient()
    {
        NetWorker socket = null;

        Networking.LanDiscovery(PORT);
        Networking.lanEndPointFound += (target) =>
        {
            isBusyFindingLan = false;
            if (target == null)
            {
                Debug.Log("No server found on LAN");
                return;
            }

            string ipAddress  = string.Empty;
            ushort targetPort = PORT;

            ipAddress  = target.Address.ToString();
            targetPort = (ushort)target.Port;

            socket = Networking.Connect(ipAddress, targetPort, Networking.TransportationProtocolType.UDP, false, false);

            Networking.SetPrimarySocket(socket);
        };
    }
 public override void Connect(string ip)
 {
     Networking.Connect(
         ip,
         Port,
         Networking.TransportationProtocolType.UDP);
 }
Пример #5
0
    private void FinalizeJoin(HostInfo host)
    {
        NetWorker socket = Networking.Connect(host.IpAddress, host.port,
                                              host.connectionType == "udp" ? Networking.TransportationProtocolType.UDP : Networking.TransportationProtocolType.TCP, isWinRT);

        if (socket.Connected)
        {
            Networking.SetPrimarySocket(socket);
#if UNITY_4_6 || UNITY_4_7
            Application.LoadLevel(host.sceneName);
#else
            BeardedManStudios.Network.Unity.UnitySceneManager.LoadScene(host.sceneName);
#endif
        }
        else
        {
            socket.connected += delegate()
            {
                Networking.SetPrimarySocket(socket);
#if UNITY_4_6 || UNITY_4_7
                Application.LoadLevel(host.sceneName);
#else
                BeardedManStudios.Network.Unity.UnitySceneManager.LoadScene(host.sceneName);
#endif
            };
        }
    }
Пример #6
0
        public void StartClient()
        {
            host = ipAddressInput.text;

            if (string.IsNullOrEmpty(host.Trim()))
            {
                Debug.Log("No ip address provided to connect to");
                return;
            }

            socket = Networking.Connect(host, (ushort)port, protocolType, IsWinRT, useNatHolePunching);

            if (!socket.Connected)
            {
                socket.ConnectTimeout  = 5000;
                socket.connectTimeout += ConnectTimeout;
            }

#if !NETFX_CORE
            if (socket is CrossPlatformUDP)
            {
                ((CrossPlatformUDP)socket).networkLatencySimulationTime = networkLatencySimulationTime;
            }
#endif

            Go();
        }
Пример #7
0
        private void FoundEndpoint(IPEndPoint endpoint)
        {
            isBusyFindingLan             = false;
            Networking.lanEndPointFound -= FoundEndpoint;
            if (endpoint == null)
            {
                Debug.Log("No server found on LAN");
                return;
            }

            string ipAddress  = string.Empty;
            ushort targetPort = 0;

#if !NETFX_CORE
            ipAddress  = endpoint.Address.ToString();
            targetPort = (ushort)endpoint.Port;
#else
            ipAddress  = endpoint.ipAddress;
            targetPort = (ushort)endpoint.port;
#endif
            MainThreadManager.Run(() => {
                socket = Networking.Connect(ipAddress, targetPort, protocolType, IsWinRT, useNatHolePunching);
                Go();
            });
        }
Пример #8
0
    // Use this for initialization
    void Start()
    {
        networker = new Networking();
        networker.Connect("192.168.0.13", "51005");

        StartCoroutine(TestData());
    }
Пример #9
0
        private static void Request(string host, Action <NetWorker> call)
        {
            if (Networking.Sockets != null && Networking.Sockets.ContainsKey(PORT))
            {
                Networking.Disconnect(PORT);
            }

            NetWorker socket = Networking.Connect(host, PORT, Networking.TransportationProtocolType.UDP, standAlone: true);

            socket.MasterServerFlag = true;

            socket.AddCustomDataReadEvent(WriteCustomMapping.MASTER_SERVER_REGISTER_SERVER, null);
            socket.AddCustomDataReadEvent(WriteCustomMapping.MASTER_SERVER_UNREGISTER_SERVER, null);
            socket.AddCustomDataReadEvent(WriteCustomMapping.MASTER_SERVER_UPDATE_SERVER, null);
            socket.AddCustomDataReadEvent(WriteCustomMapping.MASTER_SERVER_GET_HOSTS, GetHostsRequestToClient);

            if (socket.Connected)
            {
                call(socket);
            }
            else
            {
                socket.connected += delegate() { call(socket); }
            };
        }
Пример #10
0
        public void StartClientLan()
        {
#if !NETFX_CORE
            System.Net.IPEndPoint endpoint = Networking.LanDiscovery((ushort)port, 5000, protocolType, IsWinRT);
#else
            IPEndPointWinRT endpoint = Networking.LanDiscovery((ushort)port, 5000, protocolType, IsWinRT);
#endif
            if (endpoint == null)
            {
                Debug.Log("No server found on LAN");
                return;
            }

            string ipAddress  = string.Empty;
            ushort targetPort = 0;

#if !NETFX_CORE
            ipAddress  = endpoint.Address.ToString();
            targetPort = (ushort)endpoint.Port;
#else
            ipAddress  = endpoint.ipAddress;
            targetPort = (ushort)endpoint.port;
#endif

            socket = Networking.Connect(ipAddress, targetPort, protocolType, IsWinRT, useNatHolePunching);
            Go();
        }
Пример #11
0
 // Start is called before the first frame update
 void Start()
 {
     if (!networking.isConnected())
     {
         networking.Connect();
         StartCoroutine(networking.ReadMessages());
     }
 }
Пример #12
0
    public void JoinButtonClickUI()
    {
        Networking.Disconnect();
        WeAreHost = false;
        string ip = ipField.text;

        Networking.Connect(ip, Port, Networking.TransportationProtocolType.UDP, true);
        AddListeners();
    }
Пример #13
0
 // Start is called before the first frame update
 void Start()
 {
     loginInfo.isLoggedIn = false;
     loginInfo.sentLogin  = false;
     if (!networking.isConnected())
     {
         networking.Connect();
         StartCoroutine(networking.ReadMessages());
     }
 }
Пример #14
0
        private async Task Connect()
        {
            UserDialogs.Instance.ShowLoading("Connecting");
            string msg = await Networking.Connect();

            UserDialogs.Instance.HideLoading();
            alert.Title   = "Connected To";
            alert.Message = msg;
            UserDialogs.Instance.Alert(alert);
        }
Пример #15
0
        public async void Connect(int gameId)
        {
            LogText.Clear();
            ChatText.Clear();
            RefreshState();

            GameId = gameId;

            await Network.Connect();

            await Network.StartReceive();

            GameId = 0;
        }
Пример #16
0
        public void TestNetworking()
        {
            // 设置服务器
            //Thread p = new Thread(Server);
            //p.Start();

            var net = new Networking();

            // 连接
            net.Connect("192.168.0.13", "51005");

            Assert.AreEqual(true, net.Connected);



            //p.Abort();
        }
Пример #17
0
        private void DoConnect()
        {
            string host     = txtHost.Text;
            string user     = txtUser.Text;
            string password = txtPassword.Text;



            string errorMessage = "";


            if (host == "")
            {
                errorMessage = "Please enter a server address";
                goto OnConnectError;
            }

            if (user == "")
            {
                errorMessage = "Please enter a username";
                goto OnConnectError;
            }

            if (password == "")
            {
                errorMessage = "Please enter a password";
            }


OnConnectError:
            if (errorMessage != "")
            {
                MessageBox.Show(errorMessage, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (m_networking.Connect(host, user, password))
            {
                btnConnect.Enabled      = false;
                btnDisconnect.Enabled   = true;
                btnFolderRemote.Enabled = true;

                toolStripStatusLabel1.Text = "Connected";
            }
        }
Пример #18
0
    private void FinalizeJoin(HostInfo host)
    {
        NetWorker socket = Networking.Connect(host.IpAddress, host.port,
                                              host.connectionType == "udp" ? Networking.TransportationProtocolType.UDP : Networking.TransportationProtocolType.TCP, isWinRT);

        if (socket.Connected)
        {
            Networking.SetPrimarySocket(socket);
            Application.LoadLevel(host.sceneName);
        }
        else
        {
            socket.connected += delegate()
            {
                Networking.SetPrimarySocket(socket);
                Application.LoadLevel(host.sceneName);
            };
        }
    }
Пример #19
0
 /// <summary>
 /// Teleport to the given room with a scene name, ip address and port.
 /// </summary>
 /// <param name="scene">Scene to load</param>
 /// <param name="host">IP address of the host</param>
 /// <param name="port">Port of the host</param>
 public static void TeleportToRoom(string scene, string host, ushort port)
 {
     BeardedManStudios.Network.Unity.UnitySceneManager.LoadScene(scene);
     Networking.Disconnect();
     Networking.Connect(host, port, Networking.TransportationProtocolType.TCP);
 }
Пример #20
0
 public void TCPLocal()
 {
     socket = Networking.Connect("127.0.0.1", (ushort)port, protocolType, IsWinRT, useNatHolePunching);
     Go();
 }
Пример #21
0
 public void JoinServer(string ip)
 {
     Networking.Connect(ip, PORT, Networking.TransportationProtocolType.UDP);
 }
Пример #22
0
 public void StartClient()
 {
     socket = Networking.Connect(host, (ushort)port, protocolType, IsWinRT);
     Go();
 }
Пример #23
0
 public void JoinRoom(string addr)
 {
     Networking.Connect(addr);
 }