Wednesday, September 3, 2008

gen_tcp {packet, http} mode - Erlang

This is a very useful undocumented feature in Erlang and very soon they are going to make it official. But there is nothing to refer in erlang documentation yet, So i thought of writing someting about this. Yaws uses this mode very largely and also, http://www.trapexit.org/A_fast_web_server_demonstrating_some_undocumented_Erlang_features

is a good resource for the people who are further interested in about this mode.

In this mode the http header lines are comming line by line and in a format which is very easy to decode and use.

Passive mode:

You can turn your socket in to passive mode by setting the option {active, false}

Request line:

{ok, {http_request, Method, { absoluteURI, http, URL, undefined, Rest}, {Maj, Min}}}

Method – GET, POST, etc

Keep in mind the full PATH you want to get is: URL ++ Rest

{Maj, MIN} is the digits of the http version (i.e: {1, 1} for HTTP/1.1, {1, 0} for HTTP/1.0) , Maj-Min-integer

A sample request line is given below,

{ok,{http_request,'GET',{absoluteURI,http,"www.google.com",undefined,

"/"},{1,0}}}

Header lines:

{ok, {http_header, _Num, Header_Name, undefined, Value}} - This is common for both request and response.

Header_Name - name of the header usually an atom but for user defined headers it can be a string.

Value - value of the header (string)

End of header:

{ok, http _eoh} – This is common for both request and response.

Response Line:

{ok, {http_response, {Maj, Min}, Code, ResContent}}

{Maj, Min} – Same as in Request line.

Code – http status code (e.g: 100, 200) - integer

ResContent – the status code description. (e.g: OK, Moved temporary) - string

Active mode

tuples like this in active mode:

{http_request, Socket, ...}
{http_response, Socket, ...}
{http_header, Socket, ...}

The other fields will be same as the passive mode. But in future they are going to change this to the following,

{http, Socket, {http_request, ...}}
{http, Socket, {http_response, ...}}
{http, Socket, {http_header, ...}}


The purpose is to make the inner tuples look the same regardless of how they were received.

Wednesday, May 14, 2008

Five Reasons why you should learn Erlang

Here are the 5 resons why you should learn Erlang according to Joe Armstrong who is also the creator of Erlang

• You want to write programs that run faster when you run them on
a multicore computer.
• You want to write fault-tolerant applications that can be modified
without taking them out of service.
• You’ve heard about “functional programming” and you’re wondering
whether the techniques really work.
• You want to use a language that has been battle tested in real
large-scale industrial products that has great libraries and an
active user community.
• You don’t want to wear your fingers out by typing lots of lines of
code.

Thursday, May 8, 2008

What a DREAM it was!!!!!!!!

Today is the last day that we all are being in our University. After to day it's all over. What a memorable period it was. Full of joys. I couldn't believe that there is no longer shouting, screaming, joking at the final year lab. The most beautiful period of life is going to over this way. How can we forget this wonderful period with all the brothers and sisters. It will be safe in our hearts through out our life.

Thursday, March 27, 2008

Trip to Kanneliya

Last two days me and my friends at the university went on a trip to Kanneliya (a biological park nere Galle). Probably it will be the last trip that we are going during our stay at the university. We all had a very nice time with each other. Thank you Asiri and Saminda for providing us meals. And Moththe(Sameera) for the Tea. Ah, Dont forget leva and Sura , the fun they gave @ nite hi hi :) .

I think the most important event is providing the gifts of appreciation to Asiri, Saliya and Saminda who had helped us a lot for the exams (By doing "kuppi") through whole four years. The commitment they put can not be measured by the awards we gave. Thank you very much Asiri, Saliya and saminda for all those things you had done for us. Also thank you Amila for arranging such an event.


Tuesday, March 4, 2008

End of a sweetest episod of life

Now its the last few months at the university. Its really hard to believe that it has now come down to the wire. A four years of sweet memories with my friends. We had Lots of joyful moments, thank you dear friend for all those memories. The best part of it is, now I'm certain that there are bunch of friends who will never let me down, who will be with me for joy and sorrow. Thats the kind of relationship each other had in the university life. Any way thats the life is all about. There is a huge future ahead and I think experience gained here will be very important to deal with it. So dear friends may success will be with you in every part of your life. Hope this is GOOD NITE & not GOOD BYE.

Monday, February 25, 2008

Accesing a veriable defined in another file in C++

This might be a very simple thing to most of the programmers. But I thought of writing this in my blog as I spent half a day finding a way to access a variable in .cpp from another .cpp(without importing the .h or defining as public inside a class.)

suppose the variable we want to access is defined as follows in the original file,

bool flag;

if you want to access this from another .cpp simply you have to do is define it with extern key word in that file,

i.e extern bool flag;

both declarations refer to the same variable "flag".

Friday, February 22, 2008

C++ threading in windows

Any one had trouble in implementing threading in C++(well, I had, as C++ directly not providing threading) . We have to use the treading support in the windows API. But it is bit difficult to directly code to the windows API using "windows.h". while I 'm searching I found the article "C++ And Threads, by Randy Charles Morin" which has implemented the threading in C++ very effectively. If you are interested I recommend you to go through it. here is the link

http://www.kbcafe.com/articles/HowTo.Thread.pdf