Socket problem (Connection refused)

C

cody

Hi I'm created a socket listening on port 1234 (it is shown that this post
is in listening mode if I use NETSTAT). Now Iam trying to connect to this
port:

IPHostEntry entry = Dns.Resolve("localhost");
serverConn = new Socket(entry.AddressList[0].AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endpoint = new IPEndPoint(entry.AddressList[0], 1234);
serverConn.Connect(endpoint);

But I get a SocketException that the remotecomputer has denied the
connection request. What could be the cause of this? Both apps running local
and I have no firewall (Win2K).

I tried Accept() in blocking and nonblocking mode on the server but neither
worked.
 
S

Supra

both server and client must have same port. i'm not familiar NETSTAST.
"the connection refused mean the other side must have same port as the
other side..
i'm only working on system.net. similar to mirc.
regards,
 
S

Sunny

Hi cody,
what happens if with listening started you call from command prompt:

telnet localhost 1234?

Also, how you create the listener?

Sunny
 
C

cody

what happens if with listening started you call from command prompt:
telnet localhost 1234?

Good idea I'll try it tomorrow in my company.
Also, how you create the listener?

I do not have the src here but I think I did it this way:

IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
socket.Bind(new IPEndPoint(ipAddress, 1234));
socket.Listen(10);
Socket s = socket.Accept(); // exception thrown here
Hi I'm created a socket listening on port 1234 (it is shown that this post
is in listening mode if I use NETSTAT). Now Iam trying to connect to this
port:

IPHostEntry entry = Dns.Resolve("localhost");
serverConn = new Socket(entry.AddressList[0].AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endpoint = new IPEndPoint(entry.AddressList[0], 1234);
serverConn.Connect(endpoint);

But I get a SocketException that the remotecomputer has denied the
connection request. What could be the cause of this? Both apps running local
and I have no firewall (Win2K).

I tried Accept() in blocking and nonblocking mode on the server but neither
worked.
 
S

Sunny

Hi,

try with:

socket.Bind(new IPEndPoint(IPAddress.Any, 1234);

this will bind the socket to all adapters.

If it works, you have to investigate why and if DNS resolve returns
different IPAddresses on the client and on the server.

Sunny

what happens if with listening started you call from command prompt:

telnet localhost 1234?

Good idea I'll try it tomorrow in my company.
Also, how you create the listener?

I do not have the src here but I think I did it this way:

IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
socket.Bind(new IPEndPoint(ipAddress, 1234));
socket.Listen(10);
Socket s = socket.Accept(); // exception thrown here
Hi I'm created a socket listening on port 1234 (it is shown that this post
is in listening mode if I use NETSTAT). Now Iam trying to connect to this
port:

IPHostEntry entry = Dns.Resolve("localhost");
serverConn = new Socket(entry.AddressList[0].AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endpoint = new IPEndPoint(entry.AddressList[0], 1234);
serverConn.Connect(endpoint);

But I get a SocketException that the remotecomputer has denied the
connection request. What could be the cause of this? Both apps running local
and I have no firewall (Win2K).

I tried Accept() in blocking and nonblocking mode on the server but neither
worked.
 
C

cody

Hi,
try with:

socket.Bind(new IPEndPoint(IPAddress.Any, 1234);

this will bind the socket to all adapters.

If it works, you have to investigate why and if DNS resolve returns
different IPAddresses on the client and on the server.


You are right, that was the problem!

Thank you!
 

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