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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TCL SOCKETS

Status
Not open for further replies.

mpirzada

Programmer
Sep 26, 2003
7
0
0
US
Hi All,

I have a server socket script that waits and handle request from the client socket. I got this script from the Brent B. Welch TCL/TK book.

I need run the script all the time so that it can wait and listen for the input from client. How can I run this as a background service? Is there any other way to keep it running all the time without any manual intervention?

Thanks for help in advance.

Regards

Mo

Here is the script:

proc Echo_Server {port} {

global echo

set echo(main) [socket -server EchoAccept $port]

}

proc EchoAccept {sock addr port} {

global echo

puts "Accept $sock from $addr port $port"

set echo(addr,$sock) [list $addr $port]

fconfigure $sock -buffering line

fileevent $sock readable [list Echo $sock]

}

proc Echo {sock} {

global echo

if {[eof $sock] || [catch {gets $sock line}]} {

# end of file or abnormal connection drop

close $sock

puts "Close $echo(addr,$sock)"

unset echo(addr,$sock)

} else {

if {[string compare $line "quit"] == 0} {

# Prevent new connections.

# Existing connections stay open.

close $echo(main)

}

puts $sock $line

}

}
Echo_Server 2500
vwait forever

 
here's a script that will run forever (until stopped)

set loopvar true
set loopcnt 0
pack [entry .e -textvariable loopcnt]
pack [button .go -text go -command bloop]
bind .e <Button-3> exit
proc bloop {} {
global loopvar loopcnt
while {$loopvar} {
update
incr loopcnt
if {$loopcnt == 2000} {set loopvar false}
after 2000
update
}
}

The right click (Button-3) in the entry will terminate it. I have set it to stop at 2000 iterations anyway but that can come out. It probably only needs 1 of the updates but I don't know which one is more efficient. The &quot;after 2000&quot; causes a 2 sec delay between iterations. What I think you want is to insert your script where I have &quot;if {$loopcnt ...&quot;. Obviously, it doesn't have to run in WISH but that makes it easier to stop.

Is that what you were after?


Bob Rashkin
rrashkin@csc.com
 
Hi Bob,

Thanks a lot for your help. I am actually looking for a way of deploying the TCL application as a Windows service. I already created my application using prowrap.

I have also used a utility called tclsvc from
But it did not work. Also I looked at:


But this is not freeware.

If you know the way to deploy the TCL application (.exe) as a service, then your help is required.

Thanks again for your help.

Thanks

Regards

MO
 
Hm. Could you describe in what way tclsvc didn't work? I know that a lot of people use it. And if you haven't already, you should check out the Tcl'ers Wiki ( starting with the page &quot;Services under Microsoft Windows NT,&quot;
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Hi,

I followed all the steps as it says in:


The one I am not sure if I am setting the value properly:

Key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\myapp
Value: TclScript, set to &quot;source c:/my/dir/where/my/script/is/myscript.tcl&quot;

I am setting the value to:

&quot;source c:/tcl/bin/soctest.tcl&quot;

with the double quotes in the beginning and end. Is it correct? Do I need to reboot? The error it is giving is when I start the service from Services Manager:

Could not start the service on local computer
Error: 1067 The process terminated unexpectedly

Need your urgent help.

Thanks a lot

Regards

MO
 
Try it without the double-quotes around the registry value. I suspect that's the problem.

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Hi Ken,

Thanks for your help. I did as you said removing the double quotes. But still it did not work. Anyway my problem is solved by using the utility in:


First I create the .exe file using prowrap and then I did as it explained in the above page. It worked fine for me.

Thanks again.

Kind Regards

MO
 
Just a side note - if you want to &quot;run it all the time&quot; and you are under one of the windoze releases (NT,2k,XP,whatever), there is a util called &quot;srvany&quot; that you can get from the resource kit.

If you wrap your code to get an EXE, you can then wrap it again with svrany and have windoze run it as a service.

srvany does the interaction with the service manager, so if your services dies, it will relaunch it after a couple of minutes.

we were using this to keep a TCL &quot;daemon&quot; alive under NT, that was doing a &quot;watched folder&quot; thing for CAD model and drawing conversions to PDF.

hope it helps.

John Lopez
Enterprise PDM Architect
lopez.john@goodrich.com
 
Hi All,

Thanks a lot for your suggestions and help.

Yes it did work with srvany. First I used prowrap to make it .exe and then srvany to run it as service.

Thanks

Kind Regards
MO

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top