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.

help with sock connections

Old posts that have not been replied to for several years.
M
Martin2k

Post by Martin2k »

but when there is no connection he give's a tcl error :sad:
[23:04] TCL error [test]: can not find channel named "sock1688"

I can't use that in my script I think, is there no better way?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Eggdrops scripted sockets, or TCL sockets are the only way.

Eggdrop sockets have proven to be incompatible with this system, and TCL sockets are not giving you any luck.

The only other option, is to use a help application.

Where your TCL script calls a third-party program using the "exec" command, and the the returned value is used for message grabbing.
M
Martin2k

Post by Martin2k »

Code: Select all

set idx [socket -async messenger.hotmail.com 1863]
while {[eof $idx] != ""} {
set data [gets $idx]
putlog "msn: $data"
}
}
is that the best way to do that?
or not? (I don't know if it works :smile: )
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

It is likely that there is no data to read right after making the connection attempt.

It is best to use the "fileevent" command to setup a script to read the details, when somthing is received.

The "eof" command returns 1 or 0 - so eof will never equal "".

the if statment should be somthing like
if {![eof $idx]} {
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Using gets isn't going to get you any farther than eggdrop sockets, because gets looks for a cr or lf. Read the msn protocol... there is a field that tells the length of the message. So, you need to parse the server message correctly, extract the length, then use the 'read' command, which lets you read an arbitrary number of bytes or characters (depending on the channel encoding).

Also, for the example you have, you shouldn't use the -async flag, because that creates an async socket, which means the socket is created, but not connected. You can't read any data from it until it is connected.

Ok, I just telnetted to the address you posted, and here is another problem with you sample code: the msn server doesn't send you anything until you've sent it something. If you send it the wrong thing, it just disconnects you.

Try this:

Code: Select all

set sock [socket messenger.hotmail.com 1863]
puts $sock "USR 1 MD5 I you@hotmail.com"
puts $sock "USR 1 MD5 S blah"
flush $sock
while {[gets $sock text] != -1} {
  putlog "Server: $text"
}
putlog "Server closed connection"
M
Martin2k

Post by Martin2k »

Thanks, But now my problem isn't gone :sad:
the tcl sockets don't read msg from server whitout the crlf :sad:
same problem as the eggdrop connect :'(

<font size=-1>[ This Message was edited by: Martin2k on 2001-10-30 08:34 ]</font>
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

use the "read" command for this, you can pass it a length (in bytes) of how many chars you want to read.

Thus, if the command header tell you the message is 130 chars long, then you use the read command to read 130 bytes
M
Martin2k

Post by Martin2k »

how can I make a while with read?

Code: Select all

[13:48] TCL error [test]: bad argument "text": should be "nonewline"
someting is wrong :sad:
M
Martin2k

Post by Martin2k »

Code: Select all

while {$text != ""} {
  set $text [read $sock]
  msn:putchan "user" "$text"
}
:smile:
But the eggdrop is stoned when there is a connection :sad:
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

You don't use the $ symbol in a set command.

Follow the links in one of my previous posts, it has a link for information on the read command, and tells you how to use it to read a certain amount of data.
M
Martin2k

Post by Martin2k »

Yes I read http://dev.scriptics.com/man/tcl8.3/TclCmd/read.htm
:smile:
And I always do set $text "lala" :sad:
stupid me
M
Martin2k

Post by Martin2k »

Is there no better way to read a socket?
When the sock is open the eggdrop do not response :sad:

Code: Select all

 
while {[validsock $sock]} {
  set text [read $sock]
  msn:putchan "user" "$text"
  putlog "msn: $text"
  if {[lindex $text 0] == "BYE"} { 
  close $sock
   }
}
proc validsock {channel} {return [expr 1 - [catch "fconfigure $channel"]]}
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

From the tcl command manual page you read:

In the first form, the read command reads all of the data from
channelId up to the end of the file.

I think that pretty much explains the problem... you are trying to read all the data from the socket up to the end of file... for a socket, that means until the connection is closed. So it's going to freeze until the socket is closed, which may be quite a while.

Your whole script is designed wrong. You need to use nonblocking sockets (read 'fconfigure') and file events (read 'fileevent') to do this.
Locked