Closed Danila24ru closed 7 years ago
If you've got console output available try setting Server.LogLevel to NetcodeLogLevel.Debug and see if it logs anything to the console when the client tries to connect. There are a lot of situations which could cause the server to simply ignore a connection request or a challenge response and make it time out on the client (generally involving failing to decrypt or read packets, connect tokens expiring, connect tokens being reused, etc), but these should be logged if you set the log level to Debug.
I spent the whole day to make it working but I can't(
I can't connect to any 192.168..
connect to 127.0.0.1 works fine.
I am added reference to UnityEngine in netcode plugin to use debug.log with
NetcodeLogLevel.Debug . It's not logging anything
Also I tryed use Hamachi but it doesn't help. (╯°□°)╯︵ ┻━┻
In general, client get ConnectionRequestTimeout = -2, Do you tryed connection in local network or internet? (non localhost)
Hm, OK let's try and see if it's even getting any packets at all.
In Utils/IO/SocketContext.cs there's a UDPSocketContext class. This class is responsible for wrapping the core UDP socket. This class has a runSocket method which is started on another thread. It looks like this:
private void runSocket()
{
while (true)
{
try
{
datagramQueue.ReadFrom(internalSocket);
// add a debug.log here (will trigger if it receives a datagram)
}
catch
{
// and a debug.log here too (will trigger if the socket closes for any reason)
return;
}
}
}
Try adding two debug logs: one directly after the ReadFrom line (which should get printed out if it ever receives a datagram), and one in the catch
block (which should get printed out if the socket ever closes). Also maybe try putting a sanity debug log in the server constructor or something, just to verify that debug logging to Unity's console is working as expected. If that gets logged, but it doesn't log any packets received, then we know it's not even receiving packets. If it logs packets being received, then it's probably some error during packet reading that causes it to simply ignore the connection.
I built dll (last commit) and I get another problem now. When run server and client (127.0.0.1): System.Net.SocketException - Only one usage of each socket address (protocol/network address/port) is normally permitted p.s. Debug.log from dll work as expected.
SocketException:
Only one usage of each socket address (protocol/network address/port) is normally permitted
at System.Net.Sockets.Socket.Bind (System.Net.EndPoint localEP) [0x00043] in <72f197ac2181426497b3cb5000e39a05>:0 at NetcodeIO.NET.Utils.IO.UDPSocketContext.Bind (System.Net.EndPoint endpoint) [0x00001] in <4be91306f5244128b73a6010197a72e1>:0 at NetcodeIO.NET.Client+<>c.<.ctor>b__34_0 (System.Net.EndPoint endpoint) [0x00029] in <4be91306f5244128b73a6010197a72e1>:0 at NetcodeIO.NET.Client.createSocket (System.Net.EndPoint endpoint) [0x00001] in <4be91306f5244128b73a6010197a72e1>:0 at NetcodeIO.NET.Client.Connect (System.Byte[] connectToken, System.Boolean autoTick) [0x00133] in <4be91306f5244128b73a6010197a72e1>:0 at NetcodeIO.NET.Client.Connect (System.Byte[] connectToken) [0x00001] in <4be91306f5244128b73a6010197a72e1>:0 at UnityNetcodeIO.NetcodeClient.Connect (System.Byte[] connectToken, System.Action clientConnected, System.Action
1[T] connectFailedCallback) [0x00051] in D:\Programs\Projects\WebUDP\Assets\UnityNetcodeIO\Scripts\Core\NetcodeClient.cs:361 at NetworkManager.connectToServer () [0x0006f] in D:\Programs\Projects\WebUDP\Assets\UnityNetcodeIO\Test\Scripts\NetworkManager.cs:68 at NetworkManager.<Start>m__3 (UnityNetcodeIO.NetcodeClient client) [0x00009] in D:\Programs\Projects\WebUDP\Assets\UnityNetcodeIO\Test\Scripts\NetworkManager.cs:47 at UnityNetcodeIO.UnityNetcode.CreateClient (UnityNetcodeIO.NetcodeIOClientProtocol protocol, System.Action
1[T] clientCreatedCallback) [0x00057] in D:\Programs\Projects\WebUDP\Assets\UnityNetcodeIO\Scripts\Core\UnityNetcode.cs:205 at NetworkManager.m__0 (UnityNetcodeIO.NetcodeIOSupportStatus supportStatus) [0x0001f] in D:\Programs\Projects\WebUDP\Assets\UnityNetcodeIO\Test\Scripts\NetworkManager.cs:43 at UnityNetcodeIO.UnityNetcode.QuerySupport (System.Action`1[T] callback) [0x00003] in D:\Programs\Projects\WebUDP\Assets\UnityNetcodeIO\Scripts\Core\UnityNetcode.cs:144 at NetworkManager.Start () [0x0000d] in D:\Programs\Projects\WebUDP\Assets\UnityNetcodeIO\Test\Scripts\NetworkManager.cs:37
Wooh, that threw me for a loop but I'm glad you caught that. The client was supposed to be binding its socket to IPAddress.Any/IPv6Any and port 0 (which tells the OS to assign any available dynamic port), but turns out it was actually binding to the server address and port instead. I've just pushed up a new commit which fixes this.
Okay, I still can't connect. So, client send packets. On host machine I have catch this packets through Wireshark. But server doesn't any react. Also. In wireshark host reply ICPM packet with error : unreachable port
local works good p.s. don't look at red errors, I just use Debug.LogError to see log in dev console in build
Are you running wireshark from the host or client? May be worth checking both. An ICMP Port Unreachable could indicate that nothing is listening on that port. How are you generating the connect token, and how are you creating/starting the server?
Wireshark(on host 192.168.1.36) catch packets from client (192.168.1.35) but nothing happen in server. server:
static readonly byte[] privateKey = new byte[]
{
0x60, 0x6a, 0xbe, 0x6e, 0xc9, 0x19, 0x10, 0xea,
0x9a, 0x65, 0x62, 0xf6, 0x6f, 0x2b, 0x30, 0xe4,
0x43, 0x71, 0xd6, 0x2c, 0xd1, 0x99, 0x27, 0x26,
0x6b, 0x3c, 0x60, 0xf4, 0xb7, 0x15, 0xab, 0xa1,
};
private static ulong ProtocolID = 0x1122334455667788L;
public Text outputText;
public Text NumClientsText;
public string PublicIP = "192.168.1.36";
public int Port = 7777;
public int MaxClients = 256;
private NetcodeServer server;
private int clients = 0;
private void Start()
{
server = UnityNetcode.CreateServer(PublicIP, Port, ProtocolID, MaxClients, privateKey);
server.internalServer.LogLevel = NetcodeLogLevel.Debug;
server.ClientConnectedEvent.AddListener(Server_OnClientConnected);
server.ClientDisconnectedEvent.AddListener(Server_OnClientDisconnected);
server.ClientMessageEvent.AddListener(Server_OnClientMessage);
server.StartServer();
logLine("Server started");
}
Client:
public GameObject player;
public InputField ipServerText;
static byte[] privateKey = new byte[]
{
0x60, 0x6a, 0xbe, 0x6e, 0xc9, 0x19, 0x10, 0xea,
0x9a, 0x65, 0x62, 0xf6, 0x6f, 0x2b, 0x30, 0xe4,
0x43, 0x71, 0xd6, 0x2c, 0xd1, 0x99, 0x27, 0x26,
0x6b, 0x3c, 0x60, 0xf4, 0xb7, 0x15, 0xab, 0xa1,
};
private static ulong ProtocolID = 0x1122334455667788L;
public static string serverIP = "192.168.1.36";
public static int serverPORT = 7777;
IPEndPoint[] ipEndPoint = new IPEndPoint[] { new IPEndPoint(IPAddress.Parse(serverIP), serverPORT)};
protected NetcodeClient client;
void Start () {
UnityNetcode.QuerySupport((supportStatus) =>
{
if (supportStatus == NetcodeIOSupportStatus.Available)
{
Debug.LogError("Netcode.IO available and ready!");
UnityNetcode.CreateClient(NetcodeIOClientProtocol.IPv4, (client) =>
{
this.client = client;
//StartCoroutine(connectToServer());
});
}
else if (supportStatus == NetcodeIOSupportStatus.Unavailable)
{
Debug.LogError("Netcode.IO not available");
}
else if (supportStatus == NetcodeIOSupportStatus.HelperNotInstalled)
{
Debug.LogError("Netcode.IO is available, but native helper is not installed");
}
});
}
//connect by pressing button in game
public void connectToServer()
{
serverIP = ipServerText.text;
ipEndPoint = new IPEndPoint[] { new IPEndPoint(IPAddress.Parse(serverIP), serverPORT) };
Debug.LogError("Generating token on client...");
TokenFactory factory = new TokenFactory(ProtocolID, privateKey);
byte[] connectToken = factory.GenerateConnectToken(ipEndPoint,300, 100, 20UL, 1UL, new byte[256]);
client.Connect(connectToken, () =>
{
Debug.LogError("Client connected to server !!!");
client.AddPayloadListener(RecievePacket);
StartCoroutine(updateStatus());
client.SetTickrate(15);
}, (error) =>
{
Debug.LogError("FAILED CONNECTION: " + error);
});
}
Could be a firewall problem (Wireshark internally uses Wincap to capture packets, and that captures packets before they are evaluated by Windows Firewall so you'd still see them reported in Wireshark even if they get blocked by the firewall) Have you tried port forwarding, or turning off the firewall altogether?
EDIT: Also, what if you connect with client and server on the same machine, but using the 192.168 address instead of 127.0.0.1?
Also, try opening a command prompt and using netstat -a -b
to list all active ports, and see if your server application is listed and listening on the correct port (or, alternatively, run resmon.exe
and switch to the Network tab, expand the Listening Ports foldout, and look for your server application)
I disabled firewall on both machines but it doesn't help.
So, I tryed do local host connection through 192.168.1.36 server ip start, and local client (on same machine) connect to 192.168.1.36 - not working. Also, in > netstat -a -b have not server.
Oh my god, I am really stupid and inattentive. So when I wrote an ip in the script and build it I not saw that IN unity inspector always was 127.0.0.1 and 7777 port and not refreshed. That is why I can't connect. I apologize to you for your time. Thanks.
Server: 192.168.1.36 port:7777 Client: 192.168.1.35 I am trying connect to 192.168.1.36 port 7777 packets coming to server but nothing happen. An issue or I am doing something wrong? (╯°□°)╯︵ ┻━┻