Re: Messaging alert



Am Wed, 08 Mar 2006 00:51:38 -0500 schrieb Fernando Quinones:

Ulrich Schöbel wrote:
Hi Fernando,

take look at Tequila (not the drink, but http://wiki.tcl.tk/1243 ).
I think it might solve your problem in a very easy way.


The LanAdmin group will not install more GNU software so I am out of
luck ussing either comm or tequila unless I can find a binary that I can
just put in my root folder.

Hi Fernando,

tell your LanAdmin group, Tcl is not GNU software. You may as well
use Tequila privately from your root folder, if you are allowed to
open server sockets (you are, it seems).


So far I have been able to create a socket and launch a tk_messageBox.
However, this will happen with any connection. I want to be able to send
a file name and other information thru the client socket to then process
in the servers. Did I mention I want to have about 2 to 3 servers
listening? These is what I have from the book.

############
# server
############


set listenSocket [socket -server Accept2 4512]

proc Accept2 {newSock addr port} {
global forever listenSocket

set choice [tk_messageBox -type yesno\ -icon info -title success\
-message "socket success, Stop server?"]

if {$choice == yes} {close $listenSocket}



vwait forever


############
# client
############



proc Socket_Client {host port timeout} {
global connected
after $timeout {set connected timeout} set sock [socket -async $host
$port]
fileevent $sock w {set connected ok}
vwait connected
if {$connected == "timeout"} {
return -code error timeout
} else {
return $sock
}
}
}
}
Socket_Client host_ip_address 4512 3500

If I got this straight at the client side, the socket is created and
saved to sock. The fileevent statement set connected to ok when sock
becomes writable. When connected changes value vwait stops waiting and
the if statement returns the value of sock.

At the server side I am listening at the port and execute Accept2 when
the socket is created. In the original proc the values of newsock addr
and port where printed. However, I miss how do the newsock(the socket
number) and host address are coming from.

The important question now is how do I send the information from the
client to the server, lets say something like a filename. Where do I
pack that information. Moreover, once I get that information on the
server how do I send a message back to the client that I am done with
processing the file.

I have more questions, but I need to understand this first. Thanks for
all your help.

Here's a simple server and client for peer to peer conversation.
It should be easy enough to understand, what's going on. It shouldn't
be a problem to extend it to your specific needs.

############
# server
############

#! /usr/local/bin/tclkit

# Server
#
# Sends:
# SOK Server ok, connection established
# ANS Answer from server
# END End of conversation, line closed
#
# Receives:
# MSG Message from client
# BYE Client terminates session

proc Accept {chan addr port} {
# setup the channel
fconfigure $chan -buffering line
fileevent $chan readable [list ReadMsg $chan]
# Acknowledge the connection
puts $chan [list SOK "Hi, I'm here"]
}

proc ReadMsg {chan} {
# read what you received, evtl. close channel
if {[gets $chan line] < 0} {
close $chan
return
}
# implement a simple protocol
switch -exact -- [lindex $line 0] {
MSG { # Message is following
set msg [lindex $line 1]
DisplayMsg $chan $msg
}
BYE { # Client terminates conversation
# ack and close
puts $chan [list END "See you later, Alligator"]
}
}
}

proc DisplayMsg {chan msg} {
# display $msg in some fancy way
# and get a message from the operator
# to be sent back to the client
puts $chan [list ANS $myAnswer]
}

socket -server Accept 12345

vwait forever


############
# client
############

#! /usr/local/bin/tclkit

# Client
#
# Sends:
# MSG my message to the server
# BYE conversation over and out
#
# Receives:
# SOK server is listening
# ANS answer from server
# END connection closed

proc GetAnswer {chan} {
# Server has something to tell me
if {[gets $chan line] < 0} {
# connection closed by server
close $chan
# inform operator and exit
exit
}
switch -exact -- [lindex $line 0] {
SOK { # connection established, send your message
puts $chan [list MSG $myMessage]
}
ANS { # Server answered to my message
# display it and get another message from the operator
# or end conversation
DisplayAnswer [lindex $line 1]
# next message
puts $chan [list MSG $myMessage]
# or end conversation
puts $chan [list BYE "I'm tired of talking to you"]
}
END { # server dropped the line, do as well
close $chan
exit
}
}
}

if {[catch {socket $host $port} chan]} {
# something's wrong, display error msg and end program
puts "NO CONNECT: $chan"
exit
}
fconfigure $chan -buffering line
fileevent $chan readable [list GetAnswer $chan]

vwait forever

#############

It's completely untested, but should work after little effort
from your side. Hope it helps.

Kind regards

Ulrich

.



Relevant Pages

  • Re: Problem in opening websites
    ... msg is "there was no XML in the response". ... the browser gets timed out (the msg is "The connection ... to the server was reset while the page was loading."). ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Problem in opening websites
    ... Perhaps post your hijackthis log here and see if anyone can help. ... msg is "there was no XML in the response". ... the browser gets timed out (the msg is "The connection ... to the server was reset while the page was loading."). ...
    (microsoft.public.windowsxp.help_and_support)
  • Problem in opening websites
    ... Firefox and Opera and the problem persists in all three of them. ... msg is "there was no XML in the response". ... the browser gets timed out (the msg is "The connection ... to the server was reset while the page was loading."). ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: smtp debugging methods
    ... server = smtplib.SMTP ... (code, msg) ... (113, 'Software caused connection abort') ... try it with port 587 instead. ...
    (comp.lang.python)
  • Re: Outgoing POP3 email missing/lost/not received
    ... Funny thing is that I have had this ISP for 8 years and it has always been ... It looks like when you last ran CEICW, you set the ISP's mail server to: ... Internet Connection Wizard. ... After the wizard completes, the following network connection ...
    (microsoft.public.windows.server.sbs)