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 

Listening to socket

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive
View previous topic :: View next topic  
Author Message
-W0kk3L-
Voice


Joined: 23 Feb 2003
Posts: 24

PostPosted: Tue Aug 30, 2005 11:13 am    Post subject: Listening to socket Reply with quote

Howdi,

I'm trying to create a tcl script that listens to a specific port. I'm sending from a C program i've written, and i want all data that is send to the bot to be displayed in a specific chan. But do i need to use this?:

if {[catch {socket -myaddr "123.456.789.012" -server Server 12345} s]}

or am i using the wrong commands? Every message needs to be accepted. I will take care of security in a different way. Anyone got a clue?
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Aug 30, 2005 11:46 am    Post subject: Reply with quote

the documentation certainly has got a clue

have you heard of website named tcl.tk? or a file named tcl-commands.doc?


Last edited by demond on Tue Aug 30, 2005 11:48 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
-W0kk3L-
Voice


Joined: 23 Feb 2003
Posts: 24

PostPosted: Tue Aug 30, 2005 11:47 am    Post subject: Reply with quote

Is that TCL for eggdrop?
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Aug 30, 2005 11:49 am    Post subject: Reply with quote

no, it's Tcl
Back to top
View user's profile Send private message Visit poster's website
-W0kk3L-
Voice


Joined: 23 Feb 2003
Posts: 24

PostPosted: Tue Aug 30, 2005 11:55 am    Post subject: Reply with quote

So for me that's most likely useless. I do found this one, but that says the server parameter only takes care of the connection, and not any data. (http://www.tcl.tk/man/tcl8.3/TclCmd/socket.htm) Can you please help out, instead of sending just a link? I don't need help with coding the whole thing. I just need help with the commands, or preferably only that line (so i can receive data).
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Aug 30, 2005 12:08 pm    Post subject: Reply with quote

did you bother to read the whole page? there's an example at the bottom
Back to top
View user's profile Send private message Visit poster's website
-W0kk3L-
Voice


Joined: 23 Feb 2003
Posts: 24

PostPosted: Tue Aug 30, 2005 1:04 pm    Post subject: Reply with quote

demond wrote:
did you bother to read the whole page? there's an example at the bottom


Yes, i bothered to read the whole page. And most likely i need some help with it, else i wouldn't ask for it. Please only reply if you can actually help. This is not helping me at all. I'm new to the socket stuff with tcl.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Aug 30, 2005 1:11 pm    Post subject: Reply with quote

so, what's your problem?

after reading that manpage, how come you are still unable to grasp socket and connection handling in Tcl? what is it exactly that you didn't understand? you don't know how to read from, how to write to, or how to implement server socket?
Back to top
View user's profile Send private message Visit poster's website
-W0kk3L-
Voice


Joined: 23 Feb 2003
Posts: 24

PostPosted: Tue Aug 30, 2005 1:17 pm    Post subject: Reply with quote

demond wrote:
so, what's your problem?

after reading that manpage, how come you are still unable to grasp socket and connection handling in Tcl? what is it exactly that you didn't understand? you don't know how to read from, how to write to, or how to implement server socket?


I don't know how to implement server socket (e.g. how to set up a listen port) and read the data from it. I think by using the command in the starttopic i can open up a socket. And as far as i can check (by sending a package to it) it works.. but i don't know how to receive the package inside eggdrop.
Back to top
View user's profile Send private message
greenbear
Owner


Joined: 24 Sep 2001
Posts: 733
Location: Norway

PostPosted: Tue Aug 30, 2005 1:22 pm    Post subject: Reply with quote

just use control
Code:
set relayport [listen 4567 script foo]
set relaychan #channel

proc foo idx {
 control $idx bar
}

proc bar {idx var} {
 putserv "PRIVMSG $::relaychan :$var"
}
Back to top
View user's profile Send private message Send e-mail
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Aug 30, 2005 5:11 pm    Post subject: Reply with quote

alternatively, you can use [socket] with -server option, then on accepting incoming connection [fconfigure] the channel for non-blocking I/O and use [fileevent] to specify your read/write handlers:
Code:

socket -server accept 1234
proc accept {chan addr port} {
   fconfigure $chan -blocking 0 -buffering line
   fileevent $chan readable [list foo $chan]
   fileevent $chan writeable [list bar $chan]
}
proc foo {chan} {
   # there is some data to read
}
proc bar {chan} {
   # you can write here
}

(note that $chan is I/O channel, not IRC channel Wink
Back to top
View user's profile Send private message Visit poster's website
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Aug 30, 2005 11:50 pm    Post subject: Reply with quote

of course, you can safely use [puts] in the read handler, since Tcl will buffer output and periodically (via Tcl's event handling mechanism, invoked by eggdrop) feed the data to the operating system until it swallows it
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive 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