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.

Listening to socket

Old posts that have not been replied to for several years.
Locked
-
-W0kk3L-
Voice
Posts: 24
Joined: Sun Feb 23, 2003 7:23 pm

Listening to socket

Post by -W0kk3L- »

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?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

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.
-
-W0kk3L-
Voice
Posts: 24
Joined: Sun Feb 23, 2003 7:23 pm

Post by -W0kk3L- »

Is that TCL for eggdrop?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

no, it's Tcl
-
-W0kk3L-
Voice
Posts: 24
Joined: Sun Feb 23, 2003 7:23 pm

Post by -W0kk3L- »

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).
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

did you bother to read the whole page? there's an example at the bottom
-
-W0kk3L-
Voice
Posts: 24
Joined: Sun Feb 23, 2003 7:23 pm

Post by -W0kk3L- »

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.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

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?
-
-W0kk3L-
Voice
Posts: 24
Joined: Sun Feb 23, 2003 7:23 pm

Post by -W0kk3L- »

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.
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

just use control

Code: Select all

set relayport [listen 4567 script foo]
set relaychan #channel

proc foo idx {
 control $idx bar
}

proc bar {idx var} {
 putserv "PRIVMSG $::relaychan :$var"
}
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

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

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 ;)
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

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
Locked