Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketException error when running project in Unity #3

Open
alastaira opened this issue Nov 26, 2016 · 20 comments
Open

SocketException error when running project in Unity #3

alastaira opened this issue Nov 26, 2016 · 20 comments

Comments

@alastaira
Copy link

Hi! I have two machines on my home network - a desktop and a laptop, both running Windows 10 64bit. When I run the HFT Unity project on the desktop (which has a wired connection to the router), everything runs great - I can connect to the server and join the game from my mobile and the laptop (either by going to happyfuntimes.net or by directly specifying the IP address of the desktop which, to be honest, I prefer)

But when I try to run the project on the laptop (which has a Wi-Fi connection to the router), I get the following error in the console:

SocketException: An address incompatible with the requested protocol was used.

System.Net.Sockets.Socket..ctor (AddressFamily family, SocketType type, ProtocolType proto)
WebSocketSharp.Net.EndPointListener..ctor (System.Net.IPAddress address, Int32 port, Boolean secure, System.String certificateFolderPath, WebSocketSharp.Net.ServerSslConfiguration sslConfig, Boolean reuseAddress)
WebSocketSharp.Net.EndPointManager.getEndPointListener (System.Net.IPAddress address, Int32 port, Boolean secure, WebSocketSharp.Net.HttpListener listener)
WebSocketSharp.Net.EndPointManager.addPrefix (System.String uriPrefix, WebSocketSharp.Net.HttpListener listener)
WebSocketSharp.Net.EndPointManager.AddListener (WebSocketSharp.Net.HttpListener listener)

The game runs, but no clients can connect. From preliminary Googling (e.g. http://stackoverflow.com/questions/24870277/an-address-incompatible-with-the-requested-protocol-was-used) it seems like this might be related to IP4/IP6 addressing -but I've had a quick poke through the HFT code and it looks like it should adapt correctly for either. I've tried disabling IP4/IP6 individually on the network adapter but no difference :)

@greggman
Copy link
Owner

So I'm checking into this but I'm having trouble repoing. I installed Windows 10 x64 but no luck. I'll try a Wifi connection next (gotta get a USB Wifi thingy)

Can you think of anything different on your Laptop vs Desktop? Is one Windows 10 x32 and the other x64? Has one got anti-virus software or something?

Maybe you could run the built in "System Information" on each, pick File->Export and attach the results here?

@greggman
Copy link
Owner

So I went and got a USB WiFi Adaptor but no error 😓

We could try a new version of WebSocketSharp

@greggman
Copy link
Owner

Download this, unzip, and put the dll it in Assets/Plugins and see if the issue goes away

websocket-sharp.dll.zip

@greggman
Copy link
Owner

One other idea of that doesn't work is check your Windows Firewall settings. The first time a HappyFunTimes app is run Windows Firewall usually tries to block it. Maybe It's possible it doesn't have permission to access the network on your laptop?

Here's what mine looks like

windows-firewall

@alastaira
Copy link
Author

Hi! Thanks for the suggestions.

  • Both computers are running Windows 10 64 bit.
  • Trying the new version of websocket-sharp made no difference
  • My firewall settings are certainly different from yours though. On my laptop (the one that produces the error), I don't see any entries on the firewall rules list for "Unity Editor", although I do have an entry for "Unity.exe" (see attached). This machine has Unity 5.3.3f1 (64bit) installed.
    firewall_laptop

@alastaira
Copy link
Author

My desktop, meanwhile (which does work) does have (lots!) of entries for "Unity Editor", as follows: (it also has several different versions of Unity installed though - 4.6, 5.1, 5.3 and 5.4):
firewallrules_desktop

@alastaira
Copy link
Author

Just tried explicitly turning off the Firewall completely on the laptop, but that didn't help. I guess the "unity.exe" / "Unity Editor" entry in the firewall settings is a red herring.

I've tried comparing the network settings reported by ipconfig for the two machines, and they seem to match for that connection (i.e. the Local Area Connection for the desktop and the Wireless LAN for the laptop match in terms of DHCP/DNS/Gateway etc.).
However, both machines also have other adapters listed (tunnel adapters, Virtual VMWare adapters etc.) that differ. Is it possible that websocket is trying to use the wrong adapter?

@greggman
Copy link
Owner

greggman commented Nov 27, 2016

It's possible. It should be connecting to 0.0.0.0 which is all adapators. I wonder if it's one of the tunnel or VMWare adaptors

I don't think this will help but you could go to Window->HappyFunTimes->Settings and in the Debug area put a *

Run it, quit unity, and drag and drop the editor.log here.

https://docs.unity3d.com/Manual/LogFiles.html

I think it's the editor.log we want, not the player.log. You can look inside and see if there are happyfuntimes lines. I think you need to quit unity so it closes the file before you can copy it.

Sadly the time difference. It's 4:30am in Tokyo so I need to go to sleep. I'll take a look in the morning

@alastaira
Copy link
Author

There's a StartServer, then a load of HFTWebFileDB messages that all seem fine. The point around which the error is logged is here:

HFTWebServer: Ping: {"version":"0.0.0","id":"HappyFunTimes","serverName":"DESKTOP-TQLT36I: SpacePanic"}
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
HappyFunTimes.HFTLogger:Log(String) (at Assets\HappyFunTimes\HappyFunTimesCore\HFTLogger.cs:13)
HappyFunTimes.HFTLog:Info(String) (at Assets\HappyFunTimes\HappyFunTimesCore\HFTLog.cs:156)
HappyFunTimes.HFTWebServer:.ctor(HFTRuntimeOptions, String[]) (at Assets\HappyFunTimes\HappyFunTimesCore\Server\HFTWebServer.cs:40)
HappyFunTimes.HFTManager:StartServer() (at Assets\HappyFunTimes\HappyFunTimesCore\HFTManager.cs:272)
HappyFunTimes.HFTManager:Start(HFTRuntimeOptions, GameObject) (at Assets\HappyFunTimes\HappyFunTimesCore\HFTManager.cs:57)
HappyFunTimes.HFTConnectionManager:StartHappyFunTimes() (at Assets\HappyFunTimes\HappyFunTimesCore\HFTConnectionManager.cs:54)
HappyFunTimes.PlayerSpawner:StartHappyFunTimes() (at Assets\HappyFunTimes\HappyFunTimesCore\PlayerSpawner.cs:104)
HappyFunTimes.PlayerSpawner:Start() (at Assets\HappyFunTimes\HappyFunTimesCore\PlayerSpawner.cs:172)
 
(Filename: Assets/HappyFunTimes/HappyFunTimesCore/HFTLogger.cs Line: 13)

HFTWebServer: Trying address: http://[::0]:18679
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
HappyFunTimes.HFTLogger:Log(String) (at Assets\HappyFunTimes\HappyFunTimesCore\HFTLogger.cs:13)
HappyFunTimes.HFTLog:Info(String) (at Assets\HappyFunTimes\HappyFunTimesCore\HFTLog.cs:156)
HappyFunTimes.HFTWebServer:Start() (at Assets\HappyFunTimes\HappyFunTimesCore\Server\HFTWebServer.cs:70)
HappyFunTimes.HFTManager:StartServer() (at Assets\HappyFunTimes\HappyFunTimesCore\HFTManager.cs:273)
HappyFunTimes.HFTManager:Start(HFTRuntimeOptions, GameObject) (at Assets\HappyFunTimes\HappyFunTimesCore\HFTManager.cs:57)
HappyFunTimes.HFTConnectionManager:StartHappyFunTimes() (at Assets\HappyFunTimes\HappyFunTimesCore\HFTConnectionManager.cs:54)
HappyFunTimes.PlayerSpawner:StartHappyFunTimes() (at Assets\HappyFunTimes\HappyFunTimesCore\PlayerSpawner.cs:104)
HappyFunTimes.PlayerSpawner:Start() (at Assets\HappyFunTimes\HappyFunTimesCore\PlayerSpawner.cs:172)
 
(Filename: Assets/HappyFunTimes/HappyFunTimesCore/HFTLogger.cs Line: 13)

SocketException: An address incompatible with the requested protocol was used.

  at System.Net.Sockets.Socket..ctor (AddressFamily family, SocketType type, ProtocolType proto) [0x00000] in <filename unknown>:0 
  at WebSocketSharp.Net.EndPointListener..ctor (System.Net.IPEndPoint endpoint, Boolean secure, System.String certificateFolderPath, WebSocketSharp.Net.ServerSslConfiguration sslConfig, Boolean reuseAddress) [0x00000] in <filename unknown>:0 
  at WebSocketSharp.Net.EndPointManager.addPrefix (System.String uriPrefix, WebSocketSharp.Net.HttpListener listener) [0x00000] in <filename unknown>:0 
  at WebSocketSharp.Net.EndPointManager.AddListener (WebSocketSharp.Net.HttpListener listener) [0x00000] in <filename unknown>:0 
 
(Filename:  Line: -1)

PlayerSpawner: Stopping HappyFunTimes
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
HappyFunTimes.HFTLogger:Log(String) (at Assets\HappyFunTimes\HappyFunTimesCore\HFTLogger.cs:13)
HappyFunTimes.HFTLog:Info(String) (at Assets\HappyFunTimes\HappyFunTimesCore\HFTLog.cs:156)
HappyFunTimes.PlayerSpawner:StopHappyFunTimes() (at Assets\HappyFunTimes\HappyFunTimesCore\PlayerSpawner.cs:112)
HappyFunTimes.PlayerSpawner:OnDestroy() (at Assets\HappyFunTimes\HappyFunTimesCore\PlayerSpawner.cs:186)

When comparing to the log output on the other machine that is working, there is an entry there for
HFTSite: sending: {"addresses":[192.168.1.81","[fe80::ffff:ffff:fffe]"],", "port":"18679"} before the Ping, that doesn't feature on the laptop machine....?

@alastaira
Copy link
Author

Ah - I see that the HFTSite message is related to the "Installation Mode" option which I had been tinkering with (which was enabled on the laptop and not the desktop). When I turn that off I do see the same log on both the working and not-working machine. I even get a confirmation back on the not-working machine that:

HFTSite: registered: 192.168.1.167 with happyfuntimes.net for: {"ip":"109.146...... (my ip address)

@alastaira
Copy link
Author

I've just tried disabling the Wi-Fi adapter and using the Wired Ethernet connection on the laptop machine instead, but still get the same SocketException error.

@greggman
Copy link
Owner

A few more things

Can you post your ipconfig results on both machines?

Also

Can you try commenting outAssets/HappyFunTimes/HappyFunTimesCore/HFTManager.cs line 247 ?

 List<string> addresses = new List<string>();
 // addresses.Add("http://[::0]:" + m_options.serverPort);   // <=--- THIS LINE
 #if UNITY_STANDALONE_WIN
 addresses.Add("http://0.0.0.0:" + m_options.serverPort);
 #endif

@alastaira
Copy link
Author

YES! Commenting out that line fixed it. I don't understand why, but you've got it working. Thankyou!

@greggman
Copy link
Owner

greggman commented Nov 28, 2016

Well I hope you can help me figure out why. For example I tried disabling IPv6 in Windows and it still works. I tried disabling IPv6 at an even lower level and it still worked. I tried installing virtualbox (don't have VMware for Windows) but it still worked. I can't leave that line out as then it will stop working other places. So, the question is why is it failing and how can I detect when I need that line and when I don't :(

I'm still hoping you could post the ipconfig /all results from both of your machines.

NOTE: As far as I know there's no risk in posting that info. All of that info is broadcast to every website you ever visit so it's not like it's secret info

@alastaira
Copy link
Author

alastaira commented Nov 28, 2016

I just tried my laptop on a completely different Wi-Fi connection (at a coffee shop), and still get the same behaviour - with line 247 commented out it works great, but with it left in I get the SocketException. Here's the results of ipconfig /all: (incidentally, I have no idea why this computer is called "DESKTOP-TQLT36I" - it's not a desktop, it's a laptop, but that's how it came supplied!)

Windows IP Configuration

Host Name . . . . . . . . . . . . : DESKTOP-TQLT36I
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Ethernet:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : home
Description . . . . . . . . . . . : Realtek PCIe GBE Family Controller
Physical Address. . . . . . . . . : 80-FA-5B-1C-BC-E8
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Local Area Connection* 2:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
Physical Address. . . . . . . . . : 5C-E0-C5-D7-EA-6B
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Wi-Fi 2:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel(R) Dual Band Wireless-AC 7265 #2
Physical Address. . . . . . . . . : 5C-E0-C5-D7-EA-6A
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::48f3:fe4f:7b1:5cf4%19(Preferred)
IPv4 Address. . . . . . . . . . . : 10.198.123.252(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.254.0
Lease Obtained. . . . . . . . . . : 28 November 2016 16:55:17
Lease Expires . . . . . . . . . . : 28 November 2016 17:25:17
Default Gateway . . . . . . . . . : 10.198.122.1
DHCP Server . . . . . . . . . . . : 10.1.5.9
DHCPv6 IAID . . . . . . . . . . . : 140304581
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1D-B1-39-FC-80-FA-5B-1C-BC-E8
DNS Servers . . . . . . . . . . . : 10.1.5.153
10.1.5.154
NetBIOS over Tcpip. . . . . . . . : Enabled

Tunnel adapter Local Area Connection* 3:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Teredo Tunneling Adapter
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.{F7FF1621-500E-431D-BFD9-E6B276D22AE0}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes

@greggman
Copy link
Owner

greggman commented Nov 28, 2016

Thank you for that!

I don't see anything obvious. Even stranger it shows you have an IPv6 address so it seems like it should work. Sigh....

I might just have to resort to putting a try/catch in the server to just ignore the error. I just don't want it to get lost if it's pointing out a real issue

@alastaira
Copy link
Author

alastaira commented Nov 28, 2016

I'll confess to not knowing much about IPv6 (although that definitely seems related to the issue). But looking around the code in line 36 of HFTIpUtils, I see that GetLocalIPAddress strips out the interface identifier after the % sign. Is that correct?

According to the answer given by TOOGAM at
http://superuser.com/questions/99746/why-is-there-a-percent-sign-in-the-ipv6-address, it may be necessary to specify that interface when connecting to a remote system. See his example of pinging the Google IPv6 server using ping fe80::2%14 where %14 is the local IPv6 interface identifier to use, not the remote one. So is it that that interface value needs to be stored and used when constructing the IP address of the server, rather than just stripped off?

But, like I said, I'm no expert - I'm just trying to toss out ideas to help you help me! :)

@alastaira
Copy link
Author

As crude test, I just tried hardcoding the interface identifier onto the end of the address on line 247 as
addresses.Add("http://[::0%19]:" + m_options.serverPort);

Sadly, no dice (would have been a miracle if it had worked - this is way out of my sphere of knowledge!)

@nitishmehta3
Copy link

Hi,

I know this is an old post, but might help someone else facing same issue. I was also facing same issue, i tried uninstalling antivirus program on machine and it worked. Have you tried uninstalling your Anti-virus program on your laptop? Some Anti-virus programs block websocket
connections.

Thanks,
Nitish

@saturn118
Copy link

Not OP but I resolved this issue on my machine as I was using an old ipv4 ip address instead of ipv6. Changing 127.0.0.1 to ::1 fixed it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants