Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Release Socket

5 views
Skip to first unread message

Aman

unread,
May 15, 2007, 2:16:50 AM5/15/07
to
set port 12351
set s [udp_open $port]


Hi,

I am using the above given code to lock port "12351" can someone tell
me what command should I use to release the port after its use is
over???


Thanks

Regards
Aman jain

Arjen Markus

unread,
May 15, 2007, 3:37:09 AM5/15/07
to

With the ordinary sockets (I do not know UDP) closing them is enough
- but they are not automatically closed on exit (at least not on
Windows).

My guess: udp_close $s

Regards,

Arjen

Aman

unread,
May 15, 2007, 4:07:00 AM5/15/07
to


How do we close normal sockets????

close $s

???


Arjen Markus

unread,
May 15, 2007, 4:23:18 AM5/15/07
to
> ???- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Yes, they behave as if they were ordinary files on disk (except for
the fact that you have to close
explicitly, at least on Windows).

Regards,

Arjen

Mark Janssen

unread,
May 15, 2007, 6:13:11 AM5/15/07
to
> Arjen- Hide quoted text -
>
> - Show quoted text -

Arjen,

What do you mean by saying that the sockets have to be closed
explicitly on windows? My sockets are closed when I exit the
application on Windows XP.

Mark

Mark Janssen

unread,
May 15, 2007, 6:15:23 AM5/15/07
to

close $s

Mark

Arjen Markus

unread,
May 15, 2007, 8:26:52 AM5/15/07
to
> Mark- Tekst uit oorspronkelijk bericht niet weergeven -

>
> - Tekst uit oorspronkelijk bericht weergeven -

It is an impression I got from working with sockets: sometimes I would
have
to kill my program (it being a server thingy) and then for the next
run
I would need to open a socket with another port number. Uhm, am I
confusing ports and sockets now? Anyway, that is the problem I was
referring to.

Regards,

Arjen

Darren New

unread,
May 15, 2007, 9:36:42 AM5/15/07
to
Arjen Markus wrote:
> It is an impression I got from working with sockets: sometimes I would
> have
> to kill my program (it being a server thingy) and then for the next
> run
> I would need to open a socket with another port number. Uhm, am I
> confusing ports and sockets now? Anyway, that is the problem I was
> referring to.

That's not a problem with the sockets not being closed. That's the way
TCP is designed to work. The port number on a listener socket stays
"reserved" for a certain number of seconds to prevent duplicate IP
packets originally sent to the old listener from arriving after you've
opened a new listener. UNIX does it too. There are ways to turn it off.
SO_LINGER and SO_REUSEADDR address this.

--
Darren New / San Diego, CA, USA (PST)
His kernel fu is strong.
He studied at the Shao Linux Temple.

Arjen Markus

unread,
May 15, 2007, 10:02:27 AM5/15/07
to
On 15 mei, 15:36, Darren New <d...@san.rr.com> wrote:
> Arjen Markus wrote:
> > It is an impression I got from working with sockets: sometimes I would
> > have
> > to kill my program (it being a server thingy) and then for the next
> > run
> > I would need to open a socket with another port number. Uhm, am I
> > confusing ports and sockets now? Anyway, that is the problem I was
> > referring to.
>
> That's not a problem with the sockets not being closed. That's the way
> TCP is designed to work. The port number on a listener socket stays
> "reserved" for a certain number of seconds to prevent duplicate IP
> packets originally sent to the old listener from arriving after you've
> opened a new listener. UNIX does it too. There are ways to turn it off.
> SO_LINGER and SO_REUSEADDR address this.
>

Oh, that is completely new to me, but it makes sense!
So it was just my interpretation of what was happening that was odd.
Glad to know that.

Regards,

Arjen

Ed Attfield

unread,
May 15, 2007, 10:00:02 AM5/15/07
to
We've encountered a problem while using a tcl TCP connection which has
been converted to a spawn_id (so that the expect command can be used to
parse the output).

I haven't been able to construct a simple test program, so I'll have to
explain it.

Versions are expect-5.43, tcl8.4.12, SunOS 5.8.

Simplified code would be something like this:

catch {socket $server $port} serverSocket
fconfigure $serverSocket -blocking 1 -buffering line

spawn -noecho -leaveopen $serverSocket

exp_send "exit\r"

expect {
eof {
puts "got eof, and leaving"
return "bleagh"
}

timeout {
puts "timeout on command."
}

-re "prompt:" {
puts "($spawn_id) gave prompt"
}
}

On a random basis, about 1 in 20 tries, the closing TCP connection gets
ECONNRESET at the read in ExpInputProc() instead of a nice bytesRead=0.

This causes a nasty error exit instead of a call to the eof case.

ExpInputProc() should have a few lines added to it so that it looks more
like the TcpInputProc in tcl:

TcpInputProc(instanceData, buf, bufSize, errorCodePtr)

bytesRead = recv(statePtr->fd, buf, (size_t) bufSize, 0);
if (bytesRead > -1) {
return bytesRead;
}
if (errno == ECONNRESET) {
/*
* Turn ECONNRESET into a soft EOF condition.
*/
return 0;
}

--
*
* Ed Attfield phone: 613-763-3102
* Nortel Networks email: attf...@nortel.com
*
* Unix is user friendly ..
* It's just very choosy about who its friends are.
* -- anonymous

Mark Janssen

unread,
May 15, 2007, 11:04:28 AM5/15/07
to
> * Nortel Networks email: attfi...@nortel.com

> *
> * Unix is user friendly ..
> * It's just very choosy about who its friends are.
> * -- anonymous

Please file a bug report at:

http://sourceforge.net/tracker/?group_id=13179&atid=113179

Mark

0 new messages