Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

socket -server Server xxxx Behavior
I am VERY new to tcl (like I started playing with it this morning), so
please bear with me.


For a call to socket for a server like the following :

socket -server Server 21000

Create a new thread or process for the Server procedure ?


When I create multiple clients, I get the messages "puts $line" in order
for all of client one, and then client 2, etc. See the output below. If
I start all of the clients together, the first messages come out every 2
seconds (approx) and after the first client ends the subsequent clients'
messages spew out with no delays, which makes it appear to me that their
might be separate threads running but their IO is not interleaved.

Any Ideas ?

Thanks !
Joe Simon


Server code :

proc Server {channel clientaddr clientport } {
puts "Connection from $clientaddr port $clientport registered"
set line "test"
while { $line != "Done" } {
gets $channel line
puts $line
}
}

puts "Waiting For socket Connections"
socket -server Server 9902
vwait forever



Client Code :

set server localhost
set line "Test"
set count 0
set sockChan [socket $server 9902]
while { $line != "Done" && $count<10 }  {
puts $sockChan "You Stink !! --> $count"
flush $sockChan
incr count
after 2000
}
puts $sockChan "Test"
puts $sockChan "Done"
close $sockChan


Output with multiple clients running is : (I expected the messages to be
interleaved).

Waiting For socket Connections
Connection from 127.0.0.1 port 1444 registered
You Stink !! --> 0
You Stink !! --> 1
You Stink !! --> 2
You Stink !! --> 3
You Stink !! --> 4
You Stink !! --> 5
You Stink !! --> 6
You Stink !! --> 7
You Stink !! --> 8
You Stink !! --> 9
Test
Done
Connection from 127.0.0.1 port 1445 registered
You Stink !! --> 0
You Stink !! --> 1
You Stink !! --> 2
You Stink !! --> 3
You Stink !! --> 4
You Stink !! --> 5
You Stink !! --> 6
You Stink !! --> 7
You Stink !! --> 8
You Stink !! --> 9
Test
Done
Connection from 127.0.0.1 port 1446 registered
You Stink !! --> 0
You Stink !! --> 1
You Stink !! --> 2
You Stink !! --> 3
You Stink !! --> 4
You Stink !! --> 5
You Stink !! --> 6
You Stink !! --> 7
You Stink !! --> 8
You Stink !! --> 9
Test
Done






--
Joe Simon
Owego, NY
Remove .NOSPAM to send e-mail



Report this thread to moderator Post Follow-up to this message
Old Post
Joe Simon
08-31-04 01:58 AM


Re: socket -server Server xxxx Behavior
Joe Simon wrote:

> I am VERY new to tcl (like I started playing with it this morning), so
> please bear with me.
>
>
> For a call to socket for a server like the following :
>
> socket -server Server 21000
>
> Create a new thread or process for the Server procedure ?
No, Tcl has a nice feature called an "Event Loop" that is far better for
this kind of things in most situations.
>
>
> When I create multiple clients, I get the messages "puts $line" in order
> for all of client one, and then client 2, etc. See the output below. If
> I start all of the clients together, the first messages come out every 2
> seconds (approx) and after the first client ends the subsequent clients'
> messages spew out with no delays, which makes it appear to me that their
> might be separate threads running but their IO is not interleaved.

Your code just does blocking I/O. You have to look up the documentation
for the commands "socket", "fconfigure", "fileevent" to create a really
responsive server.

Take a look at:
http://wiki.tcl.tk/9414
http://wiki.tcl.tk/8301
http://wiki.tcl.tk/fileevent
http://wiki.tcl.tk/socket

The code snippets in the first two links should point you in the right
direction.

Some pointers to the event loop:
http://wiki.tcl.tk/1527
http://wiki.tcl.tk/1526

Michael

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Schlenker
08-31-04 01:58 AM


Re: socket -server Server xxxx Behavior

Michael Schlenker wrote:

> <snip>

>
> Your code just does blocking I/O. You have to look up the documentation
> for the commands "socket", "fconfigure", "fileevent" to create a really
> responsive server.
>
> Take a look at:
> http://wiki.tcl.tk/9414
> http://wiki.tcl.tk/8301
> http://wiki.tcl.tk/fileevent
> http://wiki.tcl.tk/socket
>
> The code snippets in the first two links should point you in the right
> direction.
>
> Some pointers to the event loop:
> http://wiki.tcl.tk/1527
> http://wiki.tcl.tk/1526
>
> Michael

Thanks Michael,

I'll check these out.

--
Joe Simon
Owego, NY
Remove .NOSPAM to send e-mail



Report this thread to moderator Post Follow-up to this message
Old Post
Joe Simon
09-01-04 01:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:57 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.