| View previous topic :: View next topic |
| Author |
Message |
-W0kk3L- Voice
Joined: 23 Feb 2003 Posts: 24
|
Posted: Tue Aug 30, 2005 11:13 am Post subject: Listening to socket |
|
|
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 |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Aug 30, 2005 11:46 am Post subject: |
|
|
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 |
|
 |
-W0kk3L- Voice
Joined: 23 Feb 2003 Posts: 24
|
Posted: Tue Aug 30, 2005 11:47 am Post subject: |
|
|
| Is that TCL for eggdrop? |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Aug 30, 2005 11:49 am Post subject: |
|
|
| no, it's Tcl |
|
| Back to top |
|
 |
-W0kk3L- Voice
Joined: 23 Feb 2003 Posts: 24
|
Posted: Tue Aug 30, 2005 11:55 am Post subject: |
|
|
| 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 |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Aug 30, 2005 12:08 pm Post subject: |
|
|
| did you bother to read the whole page? there's an example at the bottom |
|
| Back to top |
|
 |
-W0kk3L- Voice
Joined: 23 Feb 2003 Posts: 24
|
Posted: Tue Aug 30, 2005 1:04 pm Post subject: |
|
|
| 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 |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Aug 30, 2005 1:11 pm Post subject: |
|
|
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 |
|
 |
-W0kk3L- Voice
Joined: 23 Feb 2003 Posts: 24
|
Posted: Tue Aug 30, 2005 1:17 pm Post subject: |
|
|
| 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 |
|
 |
greenbear Owner
Joined: 24 Sep 2001 Posts: 733 Location: Norway
|
Posted: Tue Aug 30, 2005 1:22 pm Post subject: |
|
|
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 |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Aug 30, 2005 5:11 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Aug 30, 2005 11:50 pm Post subject: |
|
|
| 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 |
|
 |
|