Re: TCL multiple sockets communication



Ulrich Schöbel wrote:
Am Sun, 26 Mar 2006 08:04:34 -0800 schrieb slebetman@xxxxxxxxx:

bogdan wrote:
hey!

can anybody tell me if it is possible (in tcl) for a server to open
two(or more) sockets and to talk simultaneousley with two clients on
these two sockets?...and if yes...do you know any links with such
examples?

i tried to do it like this but it dosen't work simultaneousley...

server:

#!/usr/bin/tclsh8.4
<snipped non-concurrent code>

Use fileevents my friend.

Here's an example how to:

Server code:


... server code elided


proc accept {channel client port} {
puts "Accepted connection $channel from $client"
fconfigure $channel -translation auto -blocking 0
fileevent $channel readable "server $channel"
}

socket -server accept 1234
vwait forever


Test client code:

... client code elided

In the example above the server only opens a single port. You can
easily modify it to accept multiple ports by adding another [socket
-server accept $portnumber].

Hi Bogdan,

for mor sockets to accept connections just add a server id
to the socket and accept commands:

socket -server {accept Server1} 1234
socket -server {accept Server2} 1235
socket -server {accept Server3} 1236

proc accept {srv channel client port} {
...
}

srv will contain the server id.


Server ID's are only necessary if each port does different things
(which is what the TCP/IP model intended). But from the OPs original
example I had a feeling that he wanted all opened ports to do the same
thing. Kind of like bittorrent opening multiple listening ports but
they are all bittorent anyway. For a single service running on multiple
ports you can simply do:

socket -server accept 1234
socket -server accept 1235
socket -server accept 1236

proc accept {channel client port} {
...
}

Ulrich's example is useful for doing things like:

socket -server {accept http_server} 80
socket -server {accept pop3_server} 110
socket -server {accept custom_server} 1234

proc accept {server channel client port} {
fconfigure $channel -blocking 0
switch -exact $server {
"http_server" {
fileevent $channel readable "httpProc $channel"
}
"pop3_server" {
fileevent $channel readable "pop3Proc $channel"
}
"custom_server" {
fileevent $channel readable "myServerProc $channel"
}
}
}

.



Relevant Pages

  • Re: Structure of the multitasking server
    ... is written the maximum number of server per Check_Selector is 27. ... GNAT.Sockets.Create_Selector uses two socket and the TCP/IP sub-system ... for I in reverse S'Range loop ... This is more or less what I came up with, where the "channel" is a ...
    (comp.lang.ada)
  • Re: TCL multiple sockets communication
    ... can anybody tell me if it is possible for a server to open ... puts "Accepted connection $channel from $client" ... easily modify it to accept multiple ports by adding another [socket ... proc accept {srv channel client port} { ...
    (comp.lang.tcl)
  • Re: TCP/IP Sockets with GNAT.Sockets
    ... Send_Socket(Socket, SEA, Last); ... Socket: Socket_Type; ... Channel: Stream_Access; ... Have you tried this code with a server not Ada aware? ...
    (comp.lang.ada)
  • Re: WSADuplicateSocket IOCP 10054 10053
    ... In this case check what happen with channel of that socket (IP/ports on ... server which is required to process the request. ...
    (microsoft.public.win32.programmer.networks)
  • Re: How to terminate a socket in CLOSE_WAIT state
    ... FTP Server fixed for certain FTP clients who use both passive ... This was causing a PASSIVE opened socket to be left ... but instead expect the "half close" from the receiver. ... this sends a TCP/IP FIN packet to the ...
    (microsoft.public.win32.programmer.kernel)