Socket error

J

Jay

I have a socket listener and a test app.
The socket listener app: opens up the port 51296 and listens.
The test app - sends a message on port 51296.
If the listener and test app are on the same box, all is well - everything
works as expected.
But when I move my test app to a remote box: I get the following error:
"no connection could be made because the target machine actively refused it"
--------------------------------------------------
This is the listener code:
IPHostEntry hostEntry = Dns.GetHostEntry(myserver.domain.com);

IPEndPoint ipe = new IPEndPoint(hostEntry.AddressList[0], 51296);

Socket soc =

new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

soc.Connect(ipe);

soc.Send(Encoding.ASCII.GetBytes("some text message"));

soc.Close();

------------------------------------------------------------------------------------------------

I have firewall enabled on the server box (where the listener is running).

I tried setting the firewall options to unblock the port 51296 for all
traffic.

That did not work.

Any ideas on how to detect where the problem is..?

Thanks much

Jay
 
P

PokerMan

Definitely sounds like the firewall or some other thing cauing the issue.
You sure no other app is running that port on that machine? did you check
the client is also not blocking that port?

I usually turn off everything, antivirus progs everything (best to not be on
the net when you do this) and all firewalls. Then try, if it works i start
to put them on one by one until it doesn't work. Then fix the app causing
the block.
 
J

Jay

I cannot turn off the firewall. Its set by the corporate group policy.
I have admin previlages to modify, but not turn it off completely.

PokerMan said:
Definitely sounds like the firewall or some other thing cauing the issue.
You sure no other app is running that port on that machine? did you check
the client is also not blocking that port?

I usually turn off everything, antivirus progs everything (best to not be
on the net when you do this) and all firewalls. Then try, if it works i
start to put them on one by one until it doesn't work. Then fix the app
causing the block.



Jay said:
I have a socket listener and a test app.
The socket listener app: opens up the port 51296 and listens.
The test app - sends a message on port 51296.
If the listener and test app are on the same box, all is well -
everything works as expected.
But when I move my test app to a remote box: I get the following error:
"no connection could be made because the target machine actively refused
it"
--------------------------------------------------
This is the listener code:
IPHostEntry hostEntry = Dns.GetHostEntry(myserver.domain.com);

IPEndPoint ipe = new IPEndPoint(hostEntry.AddressList[0], 51296);

Socket soc =

new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

soc.Connect(ipe);

soc.Send(Encoding.ASCII.GetBytes("some text message"));

soc.Close();

------------------------------------------------------------------------------------------------

I have firewall enabled on the server box (where the listener is
running).

I tried setting the firewall options to unblock the port 51296 for all
traffic.

That did not work.

Any ideas on how to detect where the problem is..?

Thanks much

Jay
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

|I cannot turn off the firewall. Its set by the corporate group policy.
| I have admin previlages to modify, but not turn it off completel

Well, then how do you expect that the remote client can connect to your
server if there is a firewall?

Either you remove your firewall or at least allow that port to pass through.
 
P

PokerMan

Ignacio, at end of his post he says:

"I have firewall enabled on the server box (where the listener is running).

I tried setting the firewall options to unblock the port 51296 for all
traffic.

That did not work."

My best advice since you cant turn it off is try changing the port number
and see if you have more luck. Sounds like the firewall is the reason
though. Do check if there is anything else blocking that port.

As a check try this, start your app listening.

then open a command prompt and type Netstat -a

This shows all connections. Ensure your app is listening on the port you
mentioned. If it is then try telnet to that port and see if the server lets
that through. I am sure you'll find it doesnt due to the firewall, if it
does then there is a problem with your client end software on how it
connects.

Definitely sounds like an administrative problem not a code one though.
 
J

Jim H

Your code snippet says listener code but it looks more like client code.
Does an nslookup of myserver.domain.com return only one IP address?
Do you know which IP and/or interface AddressList[0] is binding too? Does
the server use similar code to setup the listener? Is it possible it's
binding to an IP that the remote machine does not have a route to? For
example, I have VMWare on my machine so there are 2 virtual adapters that
have private IPs that are not part of our local subnet. If my software
listened on one of those then remote machines would have no way of
connecting to me, but the same client running on my workstation would. Make
sure you are listening on the interface and IP you think you are listening
on.

jim
 
J

Jay

I am allowing that port to pass through.
But still I cannot see the messages come through.
Are there any tools that I can use to monitor what is happening?
 
J

Jim H

Your code snippet says listener code but it looks more like client code.
Does an nslookup of myserver.domain.com return only one IP address?
Do you know which IP and/or interface AddressList[0] is binding too? Does
the server use similar code to setup the listener? Is it possible it's
binding to an IP that the remote machine does not have a route to? For
example, I have VMWare on my machine so there are 2 virtual adapters that
have private IPs that are not part of our local subnet. If my software
listened on one of those then remote machines would have no way of
connecting to me, but the same client running on my workstation would. Make
sure you are listening on the interface and IP you think you are listening
on.

jim
 
J

Jay

I tried changing the port number to 80 (which is a http port and it is
unblocked)
That did not work.

I did a netstat -a .
I saw that the app was listening on the port.

But when I tried "telnet <servername> 51296", it did not go through.

What else can I do?
 
J

Jim H

Do a netstat -an and check the IP that the listener is bound to. Then try
to telnet to that IP and port instead of machine name and port. Also ping
that IP from the remote to make sure there is a route in place.


jim
 
J

Jay

I saw some thing interesting.
The server box has 2 "local area connections".
When I do an ipconfig on that box: I get 2 IP addresses.
Say for e.g: 1.1.1.1 and 2.2.2.2
When I run the listener it opens the port on 1.1.1.1 : 51296

But when I try to send the messages from my box: I only see 2.2.2.2.
I cannot ping 1.1.1.1 and therefore I cannot send messages to that box.

Any ideas why there are 2 IP addresses? Is that because of the firewall?
 
J

Jay

Found what the problem is.
I disabled one of the network connections, and now I am able to send
messages across.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top