The Artima Developer Community
Sponsored Link

Java Buzz Forum
Hello Reverser World!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
Hello Reverser World! Posted: Mar 6, 2007 11:39 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: Hello Reverser World!
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

With Joe Armstrong's new book, Programming Erlang, out in beta form I think I need to visit Erlang again. My first (and last) endeavor was a short and sweet reverser server:

-module(reverser).
-export([start/1]). 

handle_connection(ClientSock) ->
	case gen_tcp:recv(ClientSock, 0) of
		{ok, Stuff} ->
			gen_tcp:send(ClientSock, lists:reverse(Stuff)),
			handle_connection(ClientSock);
		{error, Reason} ->
			exit(Reason)
	end.

server_accept(ServerSock) ->
	{ok, ClientSock} = gen_tcp:accept(ServerSock),
	Pid = spawn(fun() -> handle_connection(ClientSock) end),
	gen_tcp:controlling_process(ClientSock, Pid),
	server_accept(ServerSock).

start(Port) ->
	{ok, ServerSock} = gen_tcp:listen(Port, [list, {active, false}]),
	spawn(fun() -> server_accept(ServerSock) end).

At the time I was very impressed with Erlang's available documentation -- I was able to make that from not knowing anything in just a couple hours, and it worked! O frabjous day!

I'm only about 50 or 60 pages into Joe's book, but those pages, at least, are extremely well written and make clear not only how to do things but what Erlang is actually doing under the covers (to some degree) which makes a world of difference.

Read: Hello Reverser World!

Topic: Dream On Previous Topic   Next Topic Topic: RSSOwl 2 Preview is out

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use