Socket based Real-Time connection

  • Thread starter Thread starter Giulio Petrucci
  • Start date Start date
G

Giulio Petrucci

Hi there,

I need to implement a sort of RTP/RTSP. Nothing impossible, just a
"minimal" implementation Anyway I need to know something more about how
could I create real-time connection using the .NET socket class. Is it
enough to write/read data in synchronous way? If not, could you link me
to some resources in the net?

Thanks in advance,
Giulio - Italia
 
I need to implement a sort of RTP/RTSP. Nothing impossible, just a
"minimal" implementation Anyway I need to know something more about how
could I create real-time connection using the .NET socket class. Is it
enough to write/read data in synchronous way? If not, could you link me
to some resources in the net?

RTP/RTSP are documented, standard protocols that are usually implemented
over UDP although you can implements them over TCP or other protocols if
you want. These protocols do not require any kind of special "real-time"
sockets (whatever that is), so the .NET Socket class is perfectly up to the
task.

If you're going to implement them, i'd highly recommend you to read "RTP -
Audio and Video for the Internet" by Colin Perkins which will provide a lot
of help in the design of your application.

For an example implementation in .NET, have a look at Microsoft's open
source Conference XP project <http://research.microsoft.com/conferencexp/>
Note that their RTP stack is not fully standard compliant though but in
case you need re-assurance that it works, then this is the proof you need.

Af for synchronous vs asynchronous socket calls, it all depends on what you
want your application to do. Synchronous appears simpler at first as it
allows you to have a single function (typically running in it own thread)
that does all the networking work, usually in a loop. It looks cleaner. But
it forces you to have one thread per client which rapidly kills performance
when the number of connected clients goes up. Asynchronous might looks more
difficult and messy at first but once you've practiced a bit, it's pretty
much straighforward and will allow your application to scale up better.
 
Hi Mehdi,

first of all: thank you for your reply.

Mehdi ha scritto:
RTP/RTSP are documented, standard protocols that are usually implemented
over UDP although you can implements them over TCP or other protocols if
you want.

I need to implementi it over TCN necessarily.
These protocols do not require any kind of special "real-time"
sockets (whatever that is), so the .NET Socket class is perfectly up to the
task.

good! :-)
If you're going to implement them, i'd highly recommend you to read "RTP -
Audio and Video for the Internet" by Colin Perkins which will provide a lot
of help in the design of your application.

Thank you for your suggestion!
For an example implementation in .NET, have a look at Microsoft's open
source Conference XP project <http://research.microsoft.com/conferencexp/>
Note that their RTP stack is not fully standard compliant though but in
case you need re-assurance that it works, then this is the proof you need.

I searched but found nothing interesting (well, I should say "I found
nothing" at all :-( ). Please, could you paste here some more detailed
links?
Af for synchronous vs asynchronous socket calls, it all depends on what you
want your application to do. Synchronous appears simpler at first as it
allows you to have a single function (typically running in it own thread)
that does all the networking work, usually in a loop. It looks cleaner. But
it forces you to have one thread per client which rapidly kills performance
when the number of connected clients goes up. Asynchronous might looks more
difficult and messy at first but once you've practiced a bit, it's pretty
much straighforward and will allow your application to scale up better.

Actually I can use async socket (I always use them when I can), but what
about the RT then? Shall I use it the same?

Thanks again!
Have a nice week,
Giulio

--
 
Mehdi ha scritto:

I need to implementi it over TCN necessarily.

I suppose that you mean TCP? Keep in mind that most real-time audio-video
systems are implemented on top of UDP rather than TCP as obviously UDP is
better suited for the task (although UDP also introduces loads of
additional problems). If you're going to do that on top of TCP, you'll need
to remember that TCP ensures that all the packets you send on the network
are received and are received in the proper order. This a good in a sense
as it means that you do not have to worry about missing or out-of-order
packets but that means that if a packets fails to be received, TCP will
keep re-sending it until it is received by the other end, hence introducing
delay which is very bad in the case of a real-time AV system. You'll need
to code to detect such delay build-up and reduce it.

You might also want to disable the Nagle algorithm on your Socket if you
want to do real-time communication over TCP.
I searched but found nothing interesting (well, I should say "I found
nothing" at all :-( ). Please, could you paste here some more detailed
links?

Conference XP is a project aimed at providing an extensible framework for
high quality audio/video conferencing. It also has other features such as
text chat, slide sharing, etc. They are using RTP over multicast UDP for
all the network communications. You can download the source code from the
main page <http://research.microsoft.com/conferencexp/>. There are several
solution and projects in there, one of which is their network stack
implementing their own non-standard-compliant RTP stack. I don't remember
how it's called, probably RTP- or Network-something. Although you probably
won't be able to re-use much or any of their code (which can not be used
for commercial purposes by the way), it should give you an idea of what
implementing RTP in .NET can look like.

You might be interested in this video as well:
<http://research.microsoft.com/conferencexp/library/workshop2005/videos/12424/default.htm>
(taken from their ressources page
<http://research.microsoft.com/conferencexp/resources_library.aspx>). It
presents an overview of Conference XP. In particular, at around 48 minutes
into the video, Jason gives a short introduction to RTP and explains how
they've implemented it in Conference XP. If you're new to RTP, this might
be useful.
Actually I can use async socket (I always use them when I can), but what
about the RT then? Shall I use it the same?

Real-time in this case simply means trying to achieve as low latency as
possible. And that has pretty much nothing to do with
synchronous/asynchronous. If you're comfortable already with asynchronous
socket programming then go for it espcially if you want you RTP stack to be
able to scale up to more than a few clients.
 
Hi Mehdi,

Mehdi ha scritto:
I suppose that you mean TCP?

Ops...
Sure: I meant TCP!
You might also want to disable the Nagle algorithm on your Socket if you
want to do real-time communication over TCP.

Good shot! I haven't thought about it before.
Real-time in this case simply means trying to achieve as low latency as
possible. And that has pretty much nothing to do with
synchronous/asynchronous. If you're comfortable already with asynchronous
socket programming then go for it espcially if you want you RTP stack to be
able to scale up to more than a few clients.

Thanks for your suggestions!

Cheers,
Giulio
 
Mehdi ha scritto:
You might also want to disable the Nagle algorithm on your Socket if you
want to do real-time communication over TCP.

....by the way: I can I disable it?
;-)

Cheers,
Giulio - Italia
 
Back
Top