ask about Network.connect function

I tried to connect a server(localhost,8010) which was developed in C++, but there was an error message “The connection request to 127.0.0.1:8010 failed.”

  • Listening port was well-operated when try to connect it by telnet.

I don’t know why it was failed. help me, please~~ :slight_smile:

the code is followed:
if(Network.peerType == NetworkPeerType.Disconnected)
{
if(GUI.Button(new Rect(10, 10, 100, 30), “Connect”))
{
if( ConnectToServer(“127.0.0.1”, 8010) )
Debug.Log(“Connect!!!”);
else
Debug.Log(“Fail!!”);
}
}
}

The Network functionality in Unity is not generic TCP, but rather a specific protocol. When you say that the server was developed in C++, I get the impression that you are trying to connect to a custom server that speaks some other protocol.

For that, you will need to use ordinary socket connections. For that, see one of the many good answers here, such as this.

The Nework system in Unity is based on RakNet. You would have to create a RakNet server in order to be able to connect via Unity’s Network.Connect but i recommend to use something different.

Unity is changing their RakNet version sometimes so there’s no guaranty that it stays compatible with your server. You can use either Sockets to setup your own networking system or when you target web-applications you should build your server also in Unity.

Sockets works also in the webplayer, but UDP is useless since Unity is checking the security policy file every time you send a packet (due to connection less protocol), TCP should be find (it just checks the policy at connect).