0
votes

I've made several games in VB successfully and am now ready to move on to attempt making multiplayer games. However, as I have no experience of doing this and can find little on the internet to assist me, I have a problem I can't find the solution to. I'm using VB as the language, although I've put c# in the tags because I can understand solutions using it instead.

I've attempted to make a game 2-player by using TCP to connect between the players.

It uses the TcpListener class for the server code and the TcpClient class for the client code and pretty much uses the template which th documentation gives: server, client.

The server:

server = New TcpListener(IPAddress.Any, 48000)

And the client:

Dim client As New TcpClient()
client.Connect(hostAddr, 48000)

I'm testing out the code using both server and client on the same machine. The code works perfectly fine when I make hostAddr the local IP address of my computer and I can successfully send messages between the 2 programs.

However, when I give hostAddr my external IP address the client code fails to work because of the error: 'No connection could be made because the target machine actively refused it'.

I have tried the following which don't work for me:

  1. Switching off the firewall

  2. Changing my router settings to allow TCP connections through all ports

I am using Windows 10 in a VM (I hope this doesn't affect things).

Could I have some suggestions as to what else could be going wrong, and how I should debug to find out if they are true? In addition, I would like to know if I would encounter similar problems if I were to ask a friend to run the client on their computer (which is not on the same network).

1

1 Answers

1
votes

You need to check the firewall settings in both the client and server machine, to start off. Most firewalls will block any incoming connection to a computer, and you'll have to open the port you want manually. So to see if this is the issue, you can temporarily disable the firewalls on both.

The next networking issue could be your HyperV configuration. I believe by default HyperV creates a "private" network switch, which means pretty much each guest OS can only talk to itself. You can create a switch so that just the VMs can talk to each other, but for development i usually choose the switch that exposes the host's network card and any guest using that hyperv switch will be seen as just another computer on your network, as if they were physicals.

All of this of course depends on how you're specifying the server; localhost should skip most of these issues, but if you're using the hostname it may be trying to use the network adapter to connect out and back in, in which case the above may come into play.