Connecting Tech Pros Worldwide Help | Site Map

Socket problem (Connection refused)

  #1  
Old November 22nd, 2005, 12:54 PM
cody
Guest
 
Posts: n/a
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


  #2  
Old November 22nd, 2005, 12:54 PM
Supra
Guest
 
Posts: n/a

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]

  #3  
Old November 22nd, 2005, 12:54 PM
Sunny
Guest
 
Posts: n/a

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]
  #4  
Old November 22nd, 2005, 12:54 PM
cody
Guest
 
Posts: n/a

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]


  #5  
Old November 22nd, 2005, 12:54 PM
Sunny
Guest
 
Posts: n/a

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]
  #6  
Old November 22nd, 2005, 12:55 PM
cody
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
socket.error connection refused Vania answers 2 November 24th, 2006 12:15 PM
Socket problem (Connection refused) cody answers 5 July 21st, 2005 04:54 PM
sending of mail (smtp) - connection refused - but smtp server isrunning! Alex Hunsley answers 4 July 18th, 2005 01:16 PM
socket object, connection refused ... Maxim Olivier-Adlhoch answers 2 July 18th, 2005 06:40 AM