TCP Client question/problem

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

I wrote a simple client / server app (nothing major, just sends text) it
works fine locally on the same system, but once i move the client to a
remote system it errors and gives me "No connection could be made because
the target machine actively refused it" what exactly does that mean? the
targed machine actively refused it? i have port forwarding set up correctly
on ISA server to forward it to the server maching...
 
I wrote a simple client / server app (nothing major, just sends text) it
works fine locally on the same system, but once i move the client to a
remote system it errors and gives me "No connection could be made because
the target machine actively refused it" what exactly does that mean? the
targed machine actively refused it? i have port forwarding set up correctly
on ISA server to forward it to the server maching...

It means that you are attempting to connect to the wrong address/port...
You may want to post a bit of code. I would suggest the code that you
use in the client to connect to the server, and probably the snippet in
the server you use to start listening.
 
Check the address where the client try to connect.. it should be the network
address of the server machine, not 127.0.0.1 or what ever was first time
when used on hte same machine as the server
 
========== client ============





==========================

Try

Dim tcpClient As New System.Net.Sockets.TcpClient

tcpClient.Connect("24.50.177.229", 9000)

Dim networkStream As NetworkStream = tcpClient.GetStream

If networkStream.CanWrite Then

Try

Dim sendBytes As Byte() = Encoding.ASCII.GetBytes("someone went to test
website")

networkStream.Write(sendBytes, 0, sendBytes.Length)

Catch ex As Exception

End Try

End If

Catch ex As Exception

Response.Write(ex.Message)

Response.Write(ex.Source)

Response.Write(ex.HelpLink)

End Try


======= server ==============
Const tcpPort As Integer = 9000
Dim localAddr As Net.IPAddress = Net.IPAddress.Parse("127.0.0.1")
Dim tcpListener As New Net.Sockets.TcpListener(localAddr, tcpPort)
Dim listnerThread As New Thread(AddressOf ListenForData)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.txtOutputMessages.Text += "Starting listener..." &
ControlChars.CrLf
tcpListener.Start()
Me.txtOutputMessages.Text += "Listener started, waiting for
connection..." & ControlChars.CrLf
Application.DoEvents()
listnerThread.Start()



End Sub

Private Sub ListenForData()
Me.txtOutputMessages.Text += "Thread started, waiting for data..." &
ControlChars.CrLf
Try
Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient
Me.txtOutputMessages.Text += "Connection Accepted..." &
ControlChars.CrLf
Dim networkStream As NetworkStream = tcpClient.GetStream()
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
Do
networkStream.Read(bytes, 0,
CInt(tcpClient.ReceiveBufferSize))
If networkStream.CanRead Then
Me.txtOutputMessages.Text += "Client Sent: " &
Encoding.ASCII.GetString(bytes) & ControlChars.CrLf
End If

Loop
Catch ex As Exception
Me.txtOutputMessages.Text = ex.Message
tcpListener.Stop()
End Try

End Sub

==========================
 
Try to Change this line's IP address to an address on the internet or the
address of the machine on the network...

Dim localAddr As Net.IPAddress = Net.IPAddress.Parse("127.0.0.1")
 
tried that, and did not work still...


scorpion53061 said:
Try to Change this line's IP address to an address on the internet or the
address of the machine on the network...

Dim localAddr As Net.IPAddress = Net.IPAddress.Parse("127.0.0.1")

data..."
 
What is the address you are port forwarding 9000 to? Is it the same as the
server IP address?
 
Hi Brain,
SO you know I am trying to connect to you at the ip you gave.....
I get the error you are desciribing thus far.....
I did a ping of your the port(ny-northtonawanda2a-485.buf.adelphia.net) you
are using and it is saying that there is a 100 percent packet loss which
means that port is not being reached...lets try another port.....
 
strangely that isnt my hostname... mine is pa-indiana.adelphia.net... I
wonder id adelphia is haveign problems ...
 
I just tried a ping here and trace rout, and my one returned
pa-indiana2b-229.pit.adelphia.net as the host and 100% packet going through
here... I wonder what is up, maybe it's an ISP problem causeing my head
aches... thanks for checking in on that for me.
 
No problem ........if you want to do some testing let me know as i have the
client sample that I think is pretty similar to yours I cna try here.
 
Have you tried changing the line from:

Dim localAddr As Net.IPAddress = Net.IPAddress.Parse("127.0.0.1")

to

Dim localAddr As Net.IPAddress = Net.IPAddress.Parse("0.0.0.0")

This tells the server to listen on all NIC addresses.
 
Back
Top