Echo server: Difference between revisions
Content added Content deleted
(→{{header|Go}}: Close client sockets when finished.) |
No edit summary |
||
Line 1,004: | Line 1,004: | ||
putStrLn $ "Accepted connection from " ++ show (host, port) |
putStrLn $ "Accepted connection from " ++ show (host, port) |
||
forkIO (echo acc)</lang> |
forkIO (echo acc)</lang> |
||
==Icon and {{header|Unicon}}== |
|||
The following is Unicon-specific: |
|||
<lang unicon>global mlck, nCons |
|||
procedure main() |
|||
mlck := mutex() |
|||
nCons := 0 |
|||
while f := open(":12321","na") do { |
|||
handle_client(f) |
|||
critical mlck: if nCons <= 0 then close(f) |
|||
} |
|||
end |
|||
procedure handle_client(f) |
|||
critical mlck: nCons +:= 1 |
|||
thread { |
|||
select(f,1000) & repeat writes(f,reads(f)) |
|||
critical mlck: nCons -:= 1 |
|||
} |
|||
end</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |