Streaming of media - java

I am trying to stream media from a server to a client. I was going to use RTSP, but in RTSP the client tells the server what to do.
I need to be able to control the media the client gets from the server. The Server tells the Client what music he wants to play.
Is there an other protocol I can use or an other way I can work around? Maybe I am wrong and you can still do this using RTSP. I need to use UDP, as I need to use multicasts, and I dont want to have to build my own protocol to keep the client synchronized.
If you need more infos, dont hestiate to use the comments field below!
Edit
This application is done in Java. I would be happy, if you could maybe tell me a mechanism that works well with Java. I am currently using the Netty library, which looks to be pretty useful (although I have not figured out how to use it yet). I don't need an answer that is based on pure network knowledge, I know how I could build a whole streaming ecosystem. I need to get this working on Java 8, without having to do the handling of the basic protocol stuff myself.

Take a look at libjitsi which is an open source Java audio/video library which can be used for streaming with encryption. It does not use Netty but it looks to be mature.

Related

How can I connect an android with a local server?

sorry if my english isn't perfect.
I'm trying to make an app and I need to exchange information between more devices.
I thought that could be a solution connect the devices on a server but I really don't have the idea where start.
What language I need to study to make this? There is a better solution?
This highly depends on what you are trying to achieve in the first place. It would be helpful if you could tell what you are trying to do, but I will still outline some general aspects:
You need to decide, what information is going to be exchanged and how this should happen
What information: Figure out, what exactly needs to be sent and received. Generic text messages? Images? Byte Streams?
How should this be done: Generally spoken, there are two approaches of getting information as a client: Polling and subscribing.
Polling: This approach means to periodically check an endpoint for new data. For example, HTTP uses this way: A web browser or any other client (REST-Client for example) periodically requests information from a HTTP-Server, using a connection just for this single request.
Subscribing / Sync / Notification: In some way or another, the client tells the server that it is interested in the information and wants to get notified when there is something new. The connection is initiated at the beginning and held open for further usage. The benefit of this approach is that changes are received immediately, but on the other hand a permanent connection needs to be maintained.
Things to study
At the beginning, get a good understanding of the TCP/IP Protocol, how Sockets work, how common Protocols do their job (e.g. HTTP, WebSockets)
Take a look at specific Protocols working on top of the basic ones
Tip: REST: Most common WebServices Protocol, providing a common way to exchange stateless data. Uses Polling.
WebSockets: Socket connection using Web Browsers. Commonly used to update information without needing to poll.
There is no specific language to learn for connections. It's more about understanding what the difficulties are and what ways have been invented to address this. Once you get to this point and know what you want to do, it's possible in every language.
Recommendation: As you seem to use Java/Android, I would try to use REST. A really great client-side library for REST on Android is Retrofit. For the server side use what fits for you .. common Java way would be to use Jersey, but you are free to choose from a lot of choices. If using Jersey is too hard for the beginning, maybe take a look at the JS/NodeJS world, those guys invented Express, which allows you to create a REST service out of just a database, wihtout having to code a lot.
First you need to decide if you want to go for an Android or an iOS application. There are other various mobile operating systems as well, but these are widely used . If you want to go for android which is most widely used in my opinion, then you need to learn Java. If you want to go for iOS application, then you need to learn swift or objectiveC. These languages provide the API to connect with various types of services such as Facebook, Firebase and Amazon etc. If you want to connect to some other local server who’s IP is known to you, then you can use socket programming to send messages.
There could be many ways you can implement this. One way will be using Web services. Of course REST might be a better option, if you follow this approach. You can implement Your service(server side code) with any language. I will recommend you use java since you are already using android.
Aside from this You might need to go through the basics of REST, its specifications and
some reference implementations for language of your preference.

Small java WebSocket Client, which supports subprotocol?

I have a WebSocket server in C (using libwebsockets) which differentiates between a few subprotocols. I now need a Java Client which is able to use different subprotocols. I tried TooTallNates Java-Websocket, but i think it dosent support different protocol types. Also i tired jetty but i cant make it work properly also it look a bit to complex for my task. i just want the possiblity to read and write messages using websocket and i dont need all those fancy extra features. Which libraries would you suggest?
If you just want to create a basic Server, you can use the ServerSocket already in java, which is pretty easy. I am currently working on a sort of groupchat in a command-prompt and I've been using this method. My first answer, so feel free to ask back. (Or give feedback)

Using a DataOutput/Input Stream with Netty?

I'm attempting to venture into non-blocking networking using Java and I had decided on using the Netty Networking Library to do so. I currently have a fully working server/client application that uses Strings to handle the networking functions. The server/client will dissasemble the strings and get the data from it; However this is not what I need to be doing.
I've been looking at the DataOutputStream and it seems it has the functions that I would like to be able to use over a network.
writeByte/readByte
writeBytes/readBytes
writeChar/readChar
writeDouble/readDouble
writeShort/readShort
writeFloat/readFloat
writeInt/readInt
writeUTF/readUTF.
Currently everything I've been doing has been in UTF Format, basically. I've just been sending bytes using (bytes[])String
I'm having a very hard time figuring out how to implement a system like this. I don't want to continue using this inefficient string based networking. It's a waste of bandwidth and I'm not learning anything doing it.
So, I found what I was looking for built into netty, I've been using it for a few days now and haven't posted back.
Inside of netty there is a ChannelBufferInputStream and a ChannelBufferOutputStream these both take in the ChannelBuffer as a parameter and allow similar functions to that of a DataStream. It has really helped me with my networking.

Using WebRTC to stream audio to java server

I'm afraid the answer to my question is no, but I'm asking it anyway just in case.
What I would like to do is stream audio from a chrome browser to a server written in Java via WebRTC. My understanding is that to accomplish this I need a Java implementation of peerconnection. All I've found so far is the libjingle Java API for android but that hasn't been particularly useful for integrating into my server app (I'd prefer an actual Java implementation, not just a C++ wrapper).
If a library to do what I want really doesn't exist does anyone have any pointers for how I might approach actually implementing the WebRTC spec myself? When I look at such a large spec I don't really know where to start.
You can use IceLink. We (I helped develop it) wrote a Java implementation for it, as well as .NET and Objective C.
This is a complete Java WebRTC signal server written with Java i/o sockets. https://code.google.com/p/jfraggws/ Just make a project, include the .Java file and include rt.jar in the project. Next set the port on the Html 5 client and plug in your servers IP. You now have java webrtc.

Tips about design/implementation of own protocol

Where I work we are in need of a protocol capable of:
User login/logout
Send/recive instructions
Send/recive files
Send/recive audio stream(could use RTP)
Send/recive small XML files Use
cryptography for all those.
It will be implemented in java. So I have some questions, since I´ve never implemeted a network protocol yet.
Is it possible to use existing protocols to build this one?
What tool can I use to help me design the protocol? for "Modeling"
Is it possible to acomplish all this, doing it alone? I have as much time as I need for this.
I have a pretty good background in Java and C++, but not yet with sockets/networking programming.
Thanks
Take a look a Google Protocol Buffers, which will generate a compact wire protocol as well as autogenerating Java message classes. I wish I'd heard of it before rolling my own message codec using Java NIO ByteBuffers.
I've got a feeling you're trying to reinvent either SIP (if your packet processing is mostly stateless and XML is small enough to go into <3k packets), or XMPP.
If you need a connection oriented login/logout, and stateful commands/instructions, then XMPP is probably closer to the requirements. Also, Jingle extension to XMPP already deals with RTP setup and teardown. XML messages are trivial to embed into custom XMPP packets (which themselves are XML) and there are known XMPP solutions for proxying a file transfer.
I'm pretty sure it meets your requirements quite well (at least the way they're presented here). If you don't have to design a completely new protocol, it's probably easier if you don't. Also reusing an existing XMPP server will allow you to solve the pain of creating your own message broker. There's OpenFire server, which is written in Java.
I dont know if this is bad advice or not, but what I usually do for my networking applications is to make a Message object that holds a TAG string and CONTENT string. The CONTENT part is usually a JSON string and the message itself is also sent to/from the server as a json string.
When the server or client receives a message, it parses the json into a Message object. You can then check the TAG part of the message to see what type of content is held in the CONTENT part of the message and decide what to do with it.
For example, if TAG=="LOGIN" then the CONTENT may be login details or similar. And when the TAG=="MESSAGE" then the CONTENT will perhaps be a json string representing your parameters, for example, who is the recipient/s and what is the content of the message, etc.
You can then do you encryption and decryption on the strings. If this is a stupid way of doing it, please tell me so in a comment so i can learn :)
I also usually implement a state design pattern on both sides, but at least on the server side. For example, the server starts out in a WaitingForLogin state. When the client logs in it switches to a different state that only listens for files and chat messages as an example. In this way I found it is a bit easier to manage.
You could use http or https. The java media framework contains an implementation of rtp.
Writing the protocol from scratch may require a lot of work. Take a look at XMPP.
If you want to write your own protocol, start with learning a form of RPC like JSON or similar, which will make your life a lot easier.

Categories

Resources