kinnay / NintendoClients

Python package to communicate with Switch, Wii U and 3DS servers
MIT License
547 stars 66 forks source link

[help] how would I create a LAN server #66

Closed korakoe closed 2 years ago

korakoe commented 3 years ago

I’m trying to create a LAN server for splatoon 2, and I need some help :/

korakoe commented 3 years ago

I know that this is for “clients” but even your examples have servers in them, so I’m wondering how I translate this to LAN instead of NEX

kinnay commented 3 years ago

Hi,

Can you give more details on what you want to achieve? There is no real server in LAN mode, because the consoles communicate directly with each other. If you want to host a LAN session on your computer, take a look at the docs for nintendo.pia.lan.serve. If done correctly, this will make your LAN session show up in the game on your Switch, but you won't be able to join it unless you implement the whole P2P protocol as well.

korakoe commented 3 years ago

I see, I have looked at the documentation but don’t fully understand it… all I want to be able to do is to be able to see it in game

kinnay commented 3 years ago

Okay, I can probably write an example script for that, but I don't have much time at the moment... If you haven't heard from me in about two weeks, feel free to post another comment on this issue to remind me of it.

korakoe commented 3 years ago

Kk

kinnay commented 3 years ago

See examples/switch/lan_host.py.

image

korakoe commented 3 years ago

thanks!

korakoe commented 3 years ago

Every time I run the script I get this error:

    sock.bind(local_address)
OSError: [WinError 10049] The requested address is not valid in its context
kinnay commented 2 years ago

https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2:

The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer.

The script should bind to your broadcast address. Can you run the following lines and check if it prints the correct IP addresses for your network?

>>> import netifaces
>>> interface = netifaces.gateways()["default"][netifaces.AF_INET][1]
>>> addresses = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]
>>> print(addresses)
{'addr': '192.168.178.188', 'netmask': '255.255.255.0', 'broadcast': '192.168.178.255'}

Unfortunately I don't have a Windows computer, so I can't check if the error is related to Windows or something else.

Sheldon10095 commented 2 years ago

See examples/switch/lan_host.py.

image

Hello! I was able to run it on my Mac(M1), but when I search in the game, it says "Unable to find a room. Search again?" Every time I have my switch search for rooms, the mac appears to see three requests, but doesn't come up.

korakoe commented 2 years ago

https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2:

The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer.

The script should bind to your broadcast address. Can you run the following lines and check if it prints the correct IP addresses for your network?

>>> import netifaces
>>> interface = netifaces.gateways()["default"][netifaces.AF_INET][1]
>>> addresses = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]
>>> print(addresses)
{'addr': '192.168.178.188', 'netmask': '255.255.255.0', 'broadcast': '192.168.178.255'}

Unfortunately I don't have a Windows computer, so I can't check if the error is related to Windows or something else.

All addresses are valid, so it's most likely a windows issue

if it comes down to it i'll probably just run it using wsl or a vm

kinnay commented 2 years ago

if it comes down to it i'll probably just run it using wsl or a vm

That should not be necessary. If the problem is caused by a bug in my code I want to fix it. It is supposed to work on any OS, including Windows.

Hello! I was able to run it on my Mac(M1), but when I search in the game, it says "Unable to find a room. Search again?" Every time I have my switch search for rooms, the mac appears to see three requests, but doesn't come up.

You're right. I just tested it on a Mac and the Switch couldn't find the room. I also noticed that tests/pia/test_lan.py is failing on my Mac. So it only works on Linux right now. I'll try to figure out what's wrong.

kinnay commented 2 years ago

Binding to the broadcast address was not a good idea apparently. See 89707db6c6a. It works on my Mac now. I still can't test it on Windows, please let me know if it works for you.

Sheldon10095 commented 2 years ago

Binding to the broadcast address was not a good idea apparently. See 89707db. It works on my Mac now. I still can't test it on Windows, please let me know if it works for you.

I does indeed work on my Mac now! Windows however is erroring with

OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
korakoe commented 2 years ago

Binding to the broadcast address was not a good idea apparently. See 89707db. It works on my Mac now. I still can't test it on Windows, please let me know if it works for you.

I does indeed work on my Mac now! Windows however is erroring with

OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

you most likely have another process hosting on the same port, the server works fine for me... try making sure that there aren't any processes using port 30000

kinnay commented 2 years ago

I am closing this issue. If I should reopen it, let me know.