Re: Windows "C" vs TCL sockets

From: David Gravereaux (davygrvy_at_pobox.com)
Date: 11/25/03


Date: Mon, 24 Nov 2003 15:04:07 -0800


"Paul Battersby" <batman42ca@yahoo.ca> wrote:

>"David Gravereaux" <davygrvy@pobox.com> wrote in message
>news:fcu4svcco864f1m4pv6aqm3mlfa3jtot78@4ax.com...
>> "Paul Battersby" <batman42ca@yahoo.ca> wrote:
>>
>> >Anything else I should know?
>>
>> socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
>
>> David Gravereaux <davygrvy@pobox.com>
>> [species: human; planet: earth,milkyway(western spiral arm),alpha sector]
>
>Ok, I tried that too. Still doesn't fix it. All I can add is that according
>to the error being returned by the windows code, the "The attempt to connect
>was forcefully rejected."
>
>The socket command returns successfully, it is the connect() call that is
>failing.

Sounds like your server isn't on an interface that's routable to the
client. Even though both are on localhost, do you have a route entry for
localhost? It should be there unless it was removed explicitly.

Did you bind() before connect()? bind() probably isn't needed. A server
placed on localhost probably isn't viewable if you try to connect to [info
hostname], but should work in the other direction. Depending on the route
table order, I've seen some windows machines place listening sockets on the
loopback rather than the first interface.

This is what I get:

C:\WINNT\system32>tclsh84
% proc foo {a b c} {}
% set s [socket -server foo 1234]
sock644
% info hostname
haleakala
%

C:\WINNT\system32>netstat -a | findstr "1234"
  TCP haleakala:1234 haleakala:0 LISTENING

C:\WINNT\system32>netstat -a -n | findstr "1234"
  TCP 0.0.0.0:1234 0.0.0.0:0 LISTENING

For me, server sockets normally are exposed. Given that Tcl's socket
command can take a bind address for both server and client, you have the
commands to fix the misunderstanding.

C:\WINNT\system32>tclsh84
% proc foo {a b c} {}
% set s [socket -server foo -myaddr localhost 1234]
sock644
%

C:\WINNT\system32>netstat -a -n | findstr "1234"
  TCP 127.0.0.1:1234 0.0.0.0:0 LISTENING

-- 
David Gravereaux <davygrvy@pobox.com>
[species: human; planet: earth,milkyway(western spiral arm),alpha sector]


Relevant Pages

  • Socket Problem: Exclusive Bind
    ... I'm developing a TCP/IP message based client and server. ... The server is intended to exclusively bind to a given interface and port. ... When I bind the listening socket for the firt time, ... _listener = new Socket(AddressFamily.InterNetwork, ...
    (microsoft.public.dotnet.framework)
  • RE: Problems with SO_REUSEADDR
    ... The SO_REUSEADDR socket option serves four different purposes: ... SO REUSEADDR allows a listening server to start and bind its well-known ... port even if previously established connections exist that use this port as ... A listening server is started. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Java Socket Constructor
    ... bind() simply binds a socket to an interface/port locally for both client ... After that you can connectto a server. ...
    (comp.lang.java.programmer)
  • Re: exclusive socket required privilige: SO_EXCLUSIVEADDRUSE
    ... Are you sure you run Winsock2 and next question: maybe such socket exist ... > listener server. ... does anyone could explain me why the bind API call ... > server with administrative rights? ...
    (microsoft.public.win32.programmer.networks)
  • Re: exclusive socket required privilige: SO_EXCLUSIVEADDRUSE
    ... Are you sure you run Winsock2 and next question: maybe such socket exist ... > listener server. ... does anyone could explain me why the bind API call ... > server with administrative rights? ...
    (microsoft.public.security)