views:

126

answers:

4

I need to maintain a connection between a server and multiple clients so that the clients can send commands, and the server trigger events. The server is basically a music-player, and the clients send commands like "Play()", "Pause()", "GetPlaylists()", etc. The server on it's side need to be able to tell the clients things like "SongEnded" or "PlayerPaused". And also, it needs to be possible to send some data to and forth (like current song, album image, playlists, etc.). I could of cause go ahead and create a socket myself and create my own protocol for handling all of the above scenarios, but chances are that someone has already done this before me, so what I really want is a framework made for real-time-communication between server and client for .NET. I've looked at xml-rpc for instance, but not sure how I should handle the "OnClientSend" with that. Also, if I'm not mistaken, xml-rpc is made to be REST-like. I've also looked at wcf, but since I have no experience with it I don't know where to start, and how to host the server in a simple console-app.

Important: The client needs to be able to not be .NET.
Important: This needs to be possible to connect to java (android).
Important: Primary platforms are windows (server and client), and Android (client).
Important: No streaming of audio is made. However, images needs to be sent.

Any ideas for a solution would be appreciated. Also, if you got links to a good framework, or descriptions of how to use components already existing inside .NET I'd be really happy.

[Edit] The problem is that when sending data over sockets there is no guarantee (at all!) that the packages you sent will be read by the server at the same time. I might send 50, then 100, then 50 bytes again, but the server might read that as a 200byte chunk, or first 100 then 100 etc, which means I need to create a buffer, read in messages until I know for certain (this is the problem) that I've received a whole message (and nothing more).

+1  A: 

You should go for WCF: http://msdn.microsoft.com/en-us/netframework/aa663324.aspx

Pierre 303
Does it support both two-way communication and running simply inside a consoll?
Alxandr
Yes it does allow that
Pierre 303
Turns out the client needs to be Net for wcf to be able to use sockets with two-way communication.
Alxandr
I never tried, so I can't help you on that.
Pierre 303
A: 

You can also look at XMPP and WebSockets. XMPP is not only limited for messaging you can always extend it for your own purpose. WebSockets is coming up well as it is part of HTML5.

ajay_whiz
A: 

I ended up creating my own simple protocol that I easily can implement in several languages. I achieved the wanted result by adding an extra layer of buffers on both sides of the socket, then sending each message followed by a byte-sequence that tells the other side that this was the end of the message. Also I added id's to the message to enable the spesial "$Return" message.

The messages are simply serialized classes using xmlserializer. Classes are generated from xsd.

Alxandr
A: 

ZeroMQ looks a good fit for your problem. Seems you've implemented something similar yourself.

  • The Supersocket library that acts as a concurrency framework.

  • Carries messages across inproc, IPC, TCP, and multicast.

  • Connect N-to-N in fanout, pubsub, pipeline, and request-reply patterns.

  • Fast enough for clustered products and supercomputing.

  • Asynchronous I/O for scalable multicore message-passing applications.

  • Large and active open source community.

  • 20+ languages including C, C++, Java, .NET, Python.

  • Most OSes including Linux, Windows, OS X.

  • LGPL free software, commercial support by iMatix Corporation.

Ed James
Yeah, but I need it to run on android.
Alxandr