Connecting Tech Pros Worldwide Help | Site Map

Socket problem (Connection refused)

cody
Guest
 
Posts: n/a
#1: Nov 22 '05
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.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk


Supra
Guest
 
Posts: n/a
#2: Nov 22 '05

re: Socket problem (Connection refused)


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,

cody wrote:
[color=blue]
>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.
>
>--
>cody
>
>Freeware Tools, Games and Humour
>http://www.deutronium.de.vu || http://www.deutronium.tk
>
>
>
>[/color]

Sunny
Guest
 
Posts: n/a
#3: Nov 22 '05

re: Socket problem (Connection refused)


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

telnet localhost 1234?

Also, how you create the listener?

Sunny


In article <#TvDGjzbEHA.1144@TK2MSFTNGP11.phx.gbl>,
no_spam_deutronium@gmx.net says...[color=blue]
> 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.
>
> --
> cody
>
> Freeware Tools, Games and Humour
> http://www.deutronium.de.vu || http://www.deutronium.tk
>
>
>[/color]
cody
Guest
 
Posts: n/a
#4: Nov 22 '05

re: Socket problem (Connection refused)


> what happens if with listening started you call from command prompt:[color=blue]
>
> telnet localhost 1234?[/color]

Good idea I'll try it tomorrow in my company.
[color=blue]
> Also, how you create the listener?[/color]

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
[color=blue]
> In article <#TvDGjzbEHA.1144@TK2MSFTNGP11.phx.gbl>,
> no_spam_deutronium@gmx.net says...[color=green]
> > Hi I'm created a socket listening on port 1234 (it is shown that this[/color][/color]
post[color=blue][color=green]
> > is in listening mode if I use NETSTAT). Now Iam trying to connect to[/color][/color]
this[color=blue][color=green]
> > 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[/color][/color]
local[color=blue][color=green]
> > and I have no firewall (Win2K).
> >
> > I tried Accept() in blocking and nonblocking mode on the server but[/color][/color]
neither[color=blue][color=green]
> > worked.[/color][/color]


Sunny
Guest
 
Posts: n/a
#5: Nov 22 '05

re: Socket problem (Connection refused)


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

In article <u2RnzF1bEHA.1408@TK2MSFTNGP12.phx.gbl>,
please_dont.spam.deutronium@gmx.de says...[color=blue][color=green]
> > what happens if with listening started you call from command prompt:
> >
> > telnet localhost 1234?[/color]
>
> Good idea I'll try it tomorrow in my company.
>[color=green]
> > Also, how you create the listener?[/color]
>
> 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
>[color=green]
> > In article <#TvDGjzbEHA.1144@TK2MSFTNGP11.phx.gbl>,
> > no_spam_deutronium@gmx.net says...[color=darkred]
> > > Hi I'm created a socket listening on port 1234 (it is shown that this[/color][/color]
> post[color=green][color=darkred]
> > > is in listening mode if I use NETSTAT). Now Iam trying to connect to[/color][/color]
> this[color=green][color=darkred]
> > > 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[/color][/color]
> local[color=green][color=darkred]
> > > and I have no firewall (Win2K).
> > >
> > > I tried Accept() in blocking and nonblocking mode on the server but[/color][/color]
> neither[color=green][color=darkred]
> > > worked.[/color][/color]
>
>
>[/color]
cody
Guest
 
Posts: n/a
#6: Nov 22 '05

re: Socket problem (Connection refused)


> Hi,[color=blue]
>
> 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.[/color]


You are right, that was the problem!

Thank you!

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk


Closed Thread