Re: Messaging alert



Fernando Quinones wrote:
Ulrich Schöbel wrote:
Am Wed, 08 Mar 2006 09:38:45 -0500 schrieb Fernando Quinones:

Can anybody help with the trouble?

You probably stopped reading my previous posting too early.
The only message I have from you is dated 2/24, is that the one your are
talking about?

Cameron, I did not went too far. Short of a binary I wont be able to
install anything in my local machine. I can decompress folders but I
cant compile anything as would on my late unix box. What you have in
mind? Here is the original post:

You realise that Tcl code does not need to be compiled right? Just
"install" (that means simply 'put') the comm package somewhere in your
local directory and use it. No compiler needed and if you don't tell
the administrators, they won't know you "installed" it ;-)


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.

Why 2 or 3 servers? You only need 1 server. Do you really understand
the concept of sockets in TCP/IP networking?

As for the rest of your message I'll reply by modifying your source
code:

############
# server
############
package require base64
array set fbuffer {}

set listenSocket [socket -server Accept2 4512]

proc Accept2 {newSock addr port} {
set choice [tk_messageBox -type yesno \
-icon info -title success \
-message "Recieved connection from client, Close connection?"]

# Why would you want to stop the server?
# Servers are supposed to run "forever":
# if {$choice == yes} {close $listenSocket}

# I think what you really want is to simply
# close this connection to the client:
if {$choice == yes} {
close $newSock
return
}

# However, if you don't close the connection,
# you can use it to transfer your "file":
fconfigure $newSock -blocking 0 -translation binary
fileevent $newSock readable "processFile $newSock"
}

processFile {sock} {
global fbuffer

# Read packet into buffer:
if {[catch {
append fbuffer($sock) [read $sock]
}] != 0 } {
tk_messageBox -type ok \
-icon error -title success \
-message "I/O error. Socket closed unexpectedly."
close $sock
return
}

# You need a protocol to know when the file
# transfer is complete. In this case I'm simply
# using the closing of the socket by the client
# as an end of transfer.

if {[eof $sock]} {
# Save the file:
# You also need a protocol to transfer the filename.
# In this case I'm sending the filename first
# followed by a newline (\n) and what follows that
# are the raw bytes from the file.

set d [string first "\n" $fbffer($sock)]
set fileName [string range $fbuffer($sock) 0 [expr $d-1]]
set fileData [string range $fbuffer($sock) [expr $d+1] end]

set fileName [tk_getSaveFile \
-title "Save file as.." \
-initialfile $fileName]
if {$fileName != ""} {
set f [open $fileName w]
puts $f $fileData
close $f
}
# Cleanup:
unset fbuffer($sock)
close $sock
}
}

vwait forever


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

proc send_File {host port filename} {
# The following code are not useful at all
# I don't know what you were trying to do:
# global connected
# after $timeout {set connected timeout}

set sock [socket $host $port]

# Again, not useful. Never in my life have I
# needed a fileevent on writable:
# fileevent $sock w {set connected ok}

# OK, from now on I'm just going to delete
# useless code. Not commenting out anymore.

fconfigure $sock -translation binary

# Remember the protocol I made up for the server
# above? Send the filename first followed by the file:

# This is how you send data to a socket:
puts $sock "$filename\n"
flush $sock
# See, just like writing to a file.

# Send the file.
set f [open $filename r]
fcopy $f $sock
close $f
close $sock
}

send_File host_ip_address 4512 testfile.txt

Now, the server code above actually does a neat trick with fileevents.
Try transferring two large files with the client program at the same
time (not one after another). See? A single server can have many
clients. You don't need 2 or 3 servers, just one server will do. What
you need is to understand how to server more than one client.

.



Relevant Pages

  • remote execution over a socket with slave interpreter
    ... Below are two scripts (for a server and for a client) that I have been using to try to set up some simple remote execution in a windows environment. ... This gave me my basic functionality, but then I decided to make it a bit more polished by creating a slave interpreter on the server side, and to feed back any results to the client side. ... proc acceptConnection {sock addr port} {global port_array ... #end of file or connection drop close $sock puts "Close $port_array" unset port_array} else {puts $line ...
    (comp.lang.tcl)
  • Reg: Multiple Clients in TCL..Please help
    ... Server Code: ... proc doService {sock msg} { ... # Call proc accept when a client attempts a connection. ...
    (comp.lang.tcl)
  • Re: Messaging alert
    ... a file name and other information thru the client socket to then process ... # Why would you want to stop the server? ... append fbuffer($sock) ... # You also need a protocol to transfer the filename. ...
    (comp.lang.tcl)
  • Re: Problem accessing Remote Object properties
    ... your object isn't as it holds the fileName and xml data between method ... created on demand by the client, so they are not shared by multiple clients. ... For that you would use RegisterActivatedServiceTypeon the server and, ... but when I then try and list the xmlFile string it ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: How to send big file use socket
    ... develop a program,when the client and server run in one computer,there is ... two computer),server always receive mutch more data than client send.How can ... This will cause all sorts of problems, including possibly getting the wrong filename, getting the wrong length value for the data being sent, and writing extra data into the file with reach read operation. ... fs.Write(buf, 0, cbRead); ...
    (microsoft.public.dotnet.languages.csharp)