Hi, I''ve started learning about EventMachine right now and have some
basic
doubts. Hope you could clarify them.
I''m developing a SIP server. For now I''ve started it from
scratch but I expect
to migrate it to EventMachine.
SIP is a very complex protocol. For example: if I use a SIP proxy in front of
my server then all the data will arrive to my server using the same TCP
connection, this means that I can''t rely on TCP
connection/disconnections.
This traffic is very similar to SMTP or HTTP. An example of SIP request would
be:
-------------------
MESSAGE sip:bob at domain.org SIP/2.0<CRLF>
From: sip:alice at domain.org;tag=qweqweqwe<CRLF>
To: sip:bob at domain.org<CRLF>
Via: xxxxxxxxx<CRLF>
Cseq: xxxxxxxxx<CRLF>
Content-Type: text/plain
Content-Length: 5
<CRLF>
hello
-------------------
Since a single TCP connection would be use (in my particular case) it means
that two requests (or more) could be groupped:
-------------------
MESSAGE sip:bob at domain.org SIP/2.0<CRLF>
From: sip:alice at domain.org;tag=qweqweqwe<CRLF>
To: sip:bob at domain.org<CRLF>
Via: xxxxxxxxx<CRLF>
Cseq: xxxxxxxxx<CRLF>
Content-Type: text/plain<CRLF>
Content-Length: 5<CRLF>
<CRLF>
helloINVITE sip:carol at domain.org SIP/2.0<CRLF>
From: sip:pepe at domain.org;tag=qweqweqwsdsde<CRLF>
To: sip:carol at domain.org<CRLF>
Via: xxxxxxxxx<CRLF>
Cseq: xxxxxxxxx<CRLF>
Content-Length: 0<CRLF>
<CRLF>
-------------------
The way to extrac each message is based on the "Content-Length"
header, so
after parsing that ammount of bytes, the remaining data is a new message.
I''ve already implemented such TCP listener and parser on my own, but
now I
wonder if it''s feasible with Event Machine (and also if EventMachine is
appropiate for this).
In order to separate each message I need to parse the headers and
count "Content-Length" bytes to read the body, so how could I generate
events
on each message extracted?
Also it could occur that there are "noise" or wrong lines between some
messages so they should be discarded.
Could you please explain me how to achieve it? (or just tell me if it''s
really
possible).
Another question is related to threads. I understand EventMachine is single
thread (since Ruby is single thread even if it uses green threads
internally). But I know that using JRuby, green threads become real system
threads so I can use all the CPU''s in my computer.
Is it possible with EventMachine when working with JRuby instead of pure Ruby?
Really thanks a lot for any help and explanation on my issues. Best regards.
--
I?aki Baz Castillo