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?
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).
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.
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?
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.
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:
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
}
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