Socket problem (Connection refused)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cody

    #1

    Socket problem (Connection refused)

    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("lo calhost");
    serverConn = new Socket(entry.Ad dressList[0].AddressFamily,
    SocketType.Stre am, ProtocolType.Tc p);
    IPEndPoint endpoint = new IPEndPoint(entr y.AddressList[0], 1234);
    serverConn.Conn ect(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

    #2
    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("lo calhost");
    >serverConn = new Socket(entry.Ad dressList[0].AddressFamily,
    >SocketType.Str eam, ProtocolType.Tc p);
    >IPEndPoint endpoint = new IPEndPoint(entr y.AddressList[0], 1234);
    >serverConn.Con nect(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]

    Comment

    • Sunny

      #3
      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.11 44@TK2MSFTNGP11 .phx.gbl>,
      no_spam_deutron ium@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("lo calhost");
      > serverConn = new Socket(entry.Ad dressList[0].AddressFamily,
      > SocketType.Stre am, ProtocolType.Tc p);
      > IPEndPoint endpoint = new IPEndPoint(entr y.AddressList[0], 1234);
      > serverConn.Conn ect(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]

      Comment

      • cody

        #4
        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.Addr essList[0];
        Socket socket = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
        ProtocolType.Tc p);
        socket.Bind(new IPEndPoint(ipAd dress, 1234));
        socket.Listen(1 0);
        Socket s = socket.Accept() ; // exception thrown here
        [color=blue]
        > In article <#TvDGjzbEHA.11 44@TK2MSFTNGP11 .phx.gbl>,
        > no_spam_deutron ium@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("lo calhost");
        > > serverConn = new Socket(entry.Ad dressList[0].AddressFamily,
        > > SocketType.Stre am, ProtocolType.Tc p);
        > > IPEndPoint endpoint = new IPEndPoint(entr y.AddressList[0], 1234);
        > > serverConn.Conn ect(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]


        Comment

        • Sunny

          #5
          Re: Socket problem (Connection refused)

          Hi,

          try with:

          socket.Bind(new IPEndPoint(IPAd dress.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.14 08@TK2MSFTNGP12 .phx.gbl>,
          please_dont.spa m.deutronium@gm x.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.Addr essList[0];
          > Socket socket = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
          > ProtocolType.Tc p);
          > socket.Bind(new IPEndPoint(ipAd dress, 1234));
          > socket.Listen(1 0);
          > Socket s = socket.Accept() ; // exception thrown here
          >[color=green]
          > > In article <#TvDGjzbEHA.11 44@TK2MSFTNGP11 .phx.gbl>,
          > > no_spam_deutron ium@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("lo calhost");
          > > > serverConn = new Socket(entry.Ad dressList[0].AddressFamily,
          > > > SocketType.Stre am, ProtocolType.Tc p);
          > > > IPEndPoint endpoint = new IPEndPoint(entr y.AddressList[0], 1234);
          > > > serverConn.Conn ect(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]

          Comment

          • cody

            #6
            Re: Socket problem (Connection refused)

            > Hi,[color=blue]
            >
            > try with:
            >
            > socket.Bind(new IPEndPoint(IPAd dress.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


            Comment

            Working...