egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problems rehashing while using sockets. [SOLVED]

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Tristam
Voice


Joined: 21 Sep 2003
Posts: 17
Location: Finland

PostPosted: Sat Dec 23, 2006 3:47 pm    Post subject: Problems rehashing while using sockets. [SOLVED] Reply with quote

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 Smile

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
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Sat Dec 23, 2006 6:39 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Tristam
Voice


Joined: 21 Sep 2003
Posts: 17
Location: Finland

PostPosted: Sat Dec 23, 2006 8:04 pm    Post subject: Reply with quote

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 Smile Could someone help?
_________________
Tristam - tristam@iki.fi
Back to top
View user's profile Send private message
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Sat Dec 23, 2006 9:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
Tristam
Voice


Joined: 21 Sep 2003
Posts: 17
Location: Finland

PostPosted: Sat Dec 23, 2006 9:55 pm    Post subject: Reply with quote

Hmm.. although I dont fully understand what it does, it seems to work Smile Thanks for your help!!!
_________________
Tristam - tristam@iki.fi
Back to top
View user's profile Send private message
KrzychuG
Master


Joined: 16 Aug 2003
Posts: 306
Location: Torun, Poland

PostPosted: Sun Dec 24, 2006 7:07 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Dec 24, 2006 10:31 pm    Post subject: Reply with quote

Also advisable to use [catch] to prevent crashes like that..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber