code...
SERVER
<code>Dim Hostname As String = Dns.GetHostName
Dim IP As String =
Dns.GetHostByName(Hostname).AddressList(0).ToStrin g
Public Sub RunServer()
Dim listener As TcpListener
Try
listener = New TcpListener(IPAddress.Parse(IP), 5001)
'wait for connection request
listener.Start()
'extablish connection upon client request
lblStatus.Text = "Waiting for connection..."
'accept an incoming connection
connection = listener.AcceptSocket
'create networkstream object associated with socket
socketStream = New NetworkStream(connection)</code>...
CLIENT
<code>
Dim client As TcpClient
Try
'create TCPClient and connect to server
client = New TcpClient
client.Connect(txtIP.Text, 5001)
'Get network stream associated with TCPClient
socketStream = client.GetStream
'create objects for writing and reading across stream
fileR = New BinaryReader(socketStream)</code>
There's the connection code. txtIP.text, as you may have guessed,
contains a string IP address (xx.xx.xx.xx). When I run this code, (yes
the server is running already) I guess this error when trying to
connect:
system.net.sockets.socketexception: No connection could be madeIt errors out at this line in the code:
because the target machine actively refused it
<code>client.Connect(txtIP.Text, 5001)</code>
When I connect just through localhost, it connects perfectly, no
problems. Also, when I change IP (the string that contains the local ip
address) to:
<code>listener = New TcpListener(IPAddress.Parse("my.ip.goes.here"),
5001)</code>
I get some error:
SocketException: The requested address is not valid in it'sAnd the error points to:
context
<code>listener.start</code>
I am on a NAT but port 5001 is fowarded. I also tried with my firewall
disabled. Is this a code problem or a network problem?
I would probably know how to fix it, except I'm going on knowledge from
about 10 pages I read in my VB.NET book (that was the whole chapter)
and they only provided examples on connecting to localhost.
Please help! :)