Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set UID and password through a socket?

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
IL
Hello,

I am connection to an IP using the socket command likr this:
set fid [socket <IP Address>]
The problem is that this IP requires UserID and password and I don't know how to put it through the open socket.
I tried:
puts $fid UserID
flush $fid

But it doesn't seem to work.
Any ideas?
 
Here is a server and client example set for you.
Client
Code:
#!/usr/bin/tclsh
set server [expr {[string length [lindex $argv 0]] > 0 ? [lindex $argv 0] : [gets stdin]}]
set port [expr {[string length [lindex $argv 1]] > 0 ? [lindex $argv 1] : [gets stdin]}]

proc sendsock {msg fd1} {

 puts $fd1 $msg
 flush $fd1

}

proc readfromsock {sck} {
                
                  if {[gets $sck line] > -1} {
                       puts $line
                       sendsock [gets stdin] $sck
                  } else {
                      after 1000;
                      readfromsock $sck
                  }
return [string length $line]
}      


  if {![catch {set client [socket $server $port]} err]} {
      while {1 && ![eof $client]} {
            readfromsock $client
      }
  } else {
       puts "ERROR: $err"
       exit
  }

Server
Code:
#!/usr/bin/tclsh
#trivial little server

set msgcount 0

proc handlestuff {sck address port} {
puts "Got connect from $address"
puts $sck "HI..welcome to stoopsrv: $address" ; flush $sck
 if {[checkpass $sck] < 1} {error "Could not determine socket fd???"}
fileevent $sck readable [list do_retr $sck]
fileevent $sck writable [list do_write $sck]
}


proc checkpass {svar} {
       if {![catch {puts [set svar]}]} {
            return 1
       }
return -1
}

proc do_retr {s} {
global msgcount 
                if {[gets $s line] > 0} {
                    puts "Read: $line at message count [incr msgcount]"
                    uplevel #0 "set lastread $line"
                    return [string length $line]
                }
}

proc do_write {s} { 
global lastread
     for {set x 0} {$x < [expr int(1+ rand() * 25)]} {incr x} {
         append str [format  %c [expr int(1 + rand() * 25)]]
     }
     #string created
     if {[binary scan $str B* var]} {
         puts $s "Random: $var"
         flush $s
     }
fconfigure stdout -blocking 0 
catch {binary scan $lastread B* var1}
catch {puts "Last input transform = $var1 and raw gen string = $str"}
}


set psock [socket -server handlestuff 2000]
vwait forever
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top