This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Problems rehashing while using sockets. [SOLVED]

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
Tristam
Voice
Posts: 17
Joined: Sun Sep 21, 2003 11:28 am
Location: Finland

Problems rehashing while using sockets. [SOLVED]

Post by Tristam »

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: Select all

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: Select all

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
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?
Last edited by Tristam on Sat Dec 23, 2006 9:56 pm, edited 1 time in total.
Tristam - tristam@iki.fi
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

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
User avatar
Tristam
Voice
Posts: 17
Joined: Sun Sep 21, 2003 11:28 am
Location: Finland

Post by Tristam »

Alchera wrote:
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
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Code: Select all

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]
}
User avatar
Tristam
Voice
Posts: 17
Joined: Sun Sep 21, 2003 11:28 am
Location: Finland

Post by Tristam »

Hmm.. although I dont fully understand what it does, it seems to work :) Thanks for your help!!!
Tristam - tristam@iki.fi
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

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?
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Also advisable to use [catch] to prevent crashes like that..
Post Reply