.NET two-way socket in real time

I need to maintain a connection between a server and multiple clients so that clients can send commands and server startup events. The server is basically a music player, and clients send commands like "Play ()", "Pause ()", "GetPlaylists ()", etc. The server on it should be able to tell clients things like "SongEnded" or "PlayerPaused." And also, you need to be able to send some data back and forth (for example, the current song, album, playlists, etc.). I could start creating a socket myself and creating my own protocol for processing all of the above scenarios, but there is a chance that someone has already done this in front of me, so what I really want is a framework created for real-time communication between the server and client for .NET. For example, I looked at xml-rpc, but I don’t know how I should handle "OnClientSend" with this. Also, if I'm not mistaken, xml-rpc is created as REST-like. I also looked at wcf, but since I have no experience with this, I don’t know where to start and how to place the server in a simple console application.

Important: The client must be able to not be .NET.
Important: It should be possible to connect to java (android).
Important: Primary platforms are windows (server and client) and Android (client).
Important: Audio is not streaming. However, images must be sent.

Any ideas for a solution would be appreciated. Also, if you have links to good frameworks or descriptions of how to use components that already exist inside .NET, I would be very happy.

[change] The problem is that when sending data via sockets there is no guarantee (in general!) that the packets you send will be considered a server at the same time. I can send 50, then 100, then 50 bytes, but the server can read this as a 200-byte chunk, or first 100, then 100, etc., Which means I need to create a buffer, read the messages until I I know for sure (this is a problem) that I received the whole message (and nothing more).

+4
source share
4 answers

As a result, I created my own simple protocol, which is easy to implement in several languages. I achieved the desired result by adding an extra layer of buffers on both sides of the socket, and then sent each message, followed by a byte sequence that tells the other side that this is the end of the message. I also added id to the message to enable the spesial "Return" message.

Messages are simply serialized classes using xmlserializer. Classes are generated from xsd.

0
source

ZeroMQ is great for your problem. It seems you have implemented something similar to yourself.

  • Supersocket library that acts as a concurrency infrastructure.

  • Sends messages through inproc, IPC, TCP and multicast.

  • Connect N-to-N to the branching, pubsub, pipeline, and request-response patterns.

  • Fast enough for clustered products and supercomputers.

  • Asynchronous I / O for scalable multi-core messaging applications.

  • A large and active open source community.

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

  • Most OSs, including Linux, Windows, OS X.

  • LGPL freeware, commercial support iMatix Corporation.

+2
source
+1
source

You can also look at XMPP and WebSockets . XMPP is not only limited to messaging, you can always expand it for your own purpose. WebSockets works well as it is part of HTML5.

0
source

All Articles