Anonymous user
Echo server: Difference between revisions
whitespace
(→{{header|Ruby}}: Add code using Socket.tcp_server_loop from Ruby 1.9.2. Keep old code for old Ruby versions.) |
(whitespace) |
||
Line 256:
=={{header|C}}==
{{works with|POSIX}}
This is a rather standard code (details apart); the reference guide for such a code is the [http://beej.us/guide/bgnet Beej's Guide to Network programming]. The dependency from POSIX is mainly in the use of the <tt>read</tt> and <tt>write</tt> functions, (using the socket as a file descriptor sometimes make things simpler).
Line 379 ⟶ 378:
=={{header|C sharp|C#}}==
<lang csharp>using System.Net.Sockets;
using System.Threading;
Line 442 ⟶ 440:
}
}
}</lang>▼
▲</lang>
=={{header|Clojure}}==
<lang lisp>(use '[clojure.contrib.server-socket :only (create-server)])
(use '[clojure.contrib.duck-streams :only (read-lines write-lines)])
Line 458 ⟶ 454:
=={{header|Common Lisp}}==
{{improve|Common Lisp|There should be a http://common-lisp.net/project/usocket/ example.}}
Sockets is not a standard part of Common Lisp but many implementations have support for this. The following example {{works with|CLISP}}
<lang lisp>(defvar *clients* '()
Line 511 ⟶ 505:
=={{header|D}}==
This is a very basic server that processes the buffers one character at a time. In a real-world application, the buffers would be larger. More seriously, it processes one listener at a time. If the <code>currSock.receive()</code> blocks, the loop will not process other clients. This opens the door for a trivial denial-of-service attack. A realistic echo service must multiplex clients.
<lang d>// Tested using DMD 2.048▼
<lang d>▼
▲// Tested using DMD 2.048
import std.socket;
import std.array;
Line 603 ⟶ 594:
=={{header|Erlang}}==
<lang erlang>-module(echo).▼
▲-module(echo).
-export([start/0]).
Line 627 ⟶ 616:
{tcp_closed, Conn} ->
io:format("Connection closed: ~p~n", [Conn])
end.</lang>
=={{header|F Sharp|F#}}==
Line 660 ⟶ 648:
let main _ =
EchoService
0</lang>
=={{header|Factor}}==
Line 746 ⟶ 733:
go echo(s, i)
}
=={{header|Haskell}}==
Line 778 ⟶ 764:
=={{header|Java}}==
<lang java>import java.io.BufferedReader;
import java.io.IOException;
Line 1,261 ⟶ 1,246:
{{omit from|PARI/GP}}
{{omit from|Retro|No concurrency support}}
{{omit from|SNUSP|No networking.}}
{{omit from|Unlambda|Does not have network access.}}
|