| View previous topic :: View next topic |
| Author |
Message |
Tristam Voice

Joined: 21 Sep 2003 Posts: 17 Location: Finland
|
Posted: Sat Dec 23, 2006 3:47 pm Post subject: Problems rehashing while using sockets. [SOLVED] |
|
|
Hello! I'm using a tcl script to exchange data between a php-website and my eggdrop.. it works fine, here's the script:
| Code: |
PHP
<?php
$msg_bt = "some text to be sent to eggdrop";
$fs = fsockopen("127.0.0.1", "1234", $errno, $errstr);
if($fs) {
fwrite($fs, $msg_bt);
fclose($fs);
}
?>
|
| Code: |
TCL
proc Server {channel clientaddr clientport} {
gets $channel msg_bt
putserv "PRIVMSG #lennonjohto :$msg_bt"
putserv "ADDLINE :$msg_bt"
close $channel
socket -server Server 1234
}
socket -server Server 1234
|
so.. this works just fine and I'm happy with it.. it's going to be part of a bigger system, not to be used like this
Anyway, this works but everytime I try to rehash the bot it crashes
| Quote: |
Tcl error in file botti.conf
couldn't open socket: address already in use
while executing
"socket -server Server 1234"
|
and the bot quits.. I got the script from somewhere and I really dont know how to use sockets.. all I know it works, but crashes when I rehash.. How to change the script/what's wrong with it? _________________ Tristam - tristam@iki.fi
Last edited by Tristam on Sat Dec 23, 2006 9:56 pm; edited 1 time in total |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Sat Dec 23, 2006 6:39 pm Post subject: |
|
|
| Quote: | | couldn't open socket: address already in use |
It had told you the problem; a socket left open. _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
Tristam Voice

Joined: 21 Sep 2003 Posts: 17 Location: Finland
|
Posted: Sat Dec 23, 2006 8:04 pm Post subject: |
|
|
| Alchera wrote: | | Quote: | | couldn't open socket: address already in use |
It had told you the problem; a socket left open. |
yeah, I figured that out.. but I'm having a hard time figuring out how to close the socket Could someone help? _________________ Tristam - tristam@iki.fi |
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Sat Dec 23, 2006 9:20 pm Post subject: |
|
|
| Code: |
if {![info exists ::socket]} {
set ::socket [socket -server Server 1234]
}
proc Server {channel clientaddr clientport} {
gets $channel msg_bt
putserv "PRIVMSG #lennonjohto :$msg_bt"
putserv "ADDLINE :$msg_bt"
close $channel
set ::socket [socket -server Server 1234]
} |
|
|
| Back to top |
|
 |
Tristam Voice

Joined: 21 Sep 2003 Posts: 17 Location: Finland
|
Posted: Sat Dec 23, 2006 9:55 pm Post subject: |
|
|
Hmm.. although I dont fully understand what it does, it seems to work Thanks for your help!!! _________________ Tristam - tristam@iki.fi |
|
| Back to top |
|
 |
KrzychuG Master

Joined: 16 Aug 2003 Posts: 306 Location: Torun, Poland
|
Posted: Sun Dec 24, 2006 7:07 am Post subject: |
|
|
| Tristam wrote: | | Hmm.. although I dont fully understand what it does, it seems to work :) Thanks for your help!!! |
It's quite simple. At the beggining you were trying to open socket every time when bot was started/restarted/rehashed. As you know you cannot bind same port to the same IP many times without closing previous connection.
You could bind a procedure to prerehash event and close your socket, then open it again after rehash or save socket name somewhere (in that case in ::socket variable) and not to open it again after rehash what was suggessted by metroid. _________________ Que? |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sun Dec 24, 2006 10:31 pm Post subject: |
|
|
| Also advisable to use [catch] to prevent crashes like that.. |
|
| Back to top |
|
 |
|