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.

Connection established

Old posts that have not been replied to for several years.
Locked
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Connection established

Post by Ofloo »

how do i check this

socket host port,

if the connection is established or not

Code: Select all

proc check:dcc {hand idx arg} {
  set hst [lindex $arg 0]
  set prt [lindex $arg 1]
  set sock [socket $hst $prt]
  if {[fileevent readable $sock] == 1} {
    putlog "Connection established"
  } else {
    putlog "Connection failed."
  }
}
i know i am missing some stuff on fileevent but how or what do i do after i found out if the connection is readable .?

i just need to know if a connection can be made to see if a certain port is open ... before i run a sript to perfrom commands on that port ...
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Code: Select all

bind dcc - check pcheck:dcc

proc check:dcc {hand idx arg} {
  set hst [lindex $arg 0]
  set prt [lindex $arg 1]
  set sock [socket $hst $prt]
  if {![eof $sock] == 1} {
    putlog "Connection established"
    close $sock
  } else {
    putlog "Connection failed."
  }
}
ok so far so good but now if the socket can't connect it shows an error .. ?

also how can i make it connect to an udp port ?
XplaiN but think of me as stupid
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Ofloo wrote:

Code: Select all

bind dcc - check pcheck:dcc

proc check:dcc {hand idx arg} {
  set hst [lindex $arg 0]
  set prt [lindex $arg 1]
  set sock [socket $hst $prt]
  if {![eof $sock] == 1} {
    putlog "Connection established"
    close $sock
  } else {
    putlog "Connection failed."
  }
}
ok so far so good but now if the socket can't connect it shows an error .. ?

also how can i make it connect to an udp port ?
TCL does not natively support udp connections. From my understanding, TCL8.4.x was supposed to include support but they decided against it. You will need to google for a TCL udp extension, or create your own.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Since you are not using async sockets, you can tell if the socket connects because if it doesn't, you'll get a tcl error.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

i know that it connects but when the error comes i got one problem .. witch is that it won't finish the script
XplaiN but think of me as stupid
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Use the "catch" command to catch errors and handle them. It's in the tcl manual.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

i know if {[catch [....] error] == 1} just do not understand the manual about that .. could you xplain it maybe little closer .. what it exactly does and what i need to think about when i script this cause ive tryed that and it sometimes did say it connected even tho there was no open port so .. euhm it did connect to the ip but .. well you get the point i think.
XplaiN but think of me as stupid
Locked