GithubHelp home page GithubHelp logo

Comments (12)

GlaireDaggers avatar GlaireDaggers commented on September 2, 2024

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.

from netcode.io.net.

Danila24ru avatar Danila24ru commented on September 2, 2024

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)

from netcode.io.net.

GlaireDaggers avatar GlaireDaggers commented on September 2, 2024

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.

from netcode.io.net.

Danila24ru avatar Danila24ru commented on September 2, 2024

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.Action1[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.Action1[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

from netcode.io.net.

GlaireDaggers avatar GlaireDaggers commented on September 2, 2024

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.

from netcode.io.net.

Danila24ru avatar Danila24ru commented on September 2, 2024

cantconnec
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.
server
Also. In wireshark host reply ICPM packet with error : unreachable port
icmp

from netcode.io.net.

Danila24ru avatar Danila24ru commented on September 2, 2024

test
local works good
p.s. don't look at red errors, I just use Debug.LogError to see log in dev console in build

from netcode.io.net.

GlaireDaggers avatar GlaireDaggers commented on September 2, 2024

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?

from netcode.io.net.

Danila24ru avatar Danila24ru commented on September 2, 2024

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);
        });
    }

from netcode.io.net.

GlaireDaggers avatar GlaireDaggers commented on September 2, 2024

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)

from netcode.io.net.

Danila24ru avatar Danila24ru commented on September 2, 2024

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.

from netcode.io.net.

Danila24ru avatar Danila24ru commented on September 2, 2024

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.

from netcode.io.net.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.