hi every body could you please help me . I write java code for sending string msg between client and server using udp socket . but I want to to send real time voice so could you please give some notes to do it
I can point you a little of the way, you probably would want to use the Real-time Transport Protocol (RTP), which is more or less the standard for sending audio or video real time over the net. However the implementation is not straight forward, and you should use a helper library like jlibrtp for the implementation. There is also a RTP packetizer in Java Media Framework (JMF), but you don't wanna go there....
UDP has no quality of service guarantee, so when sending your packets of data you will need to add some sort of order number to your data to detremine how to put the data back together. For example you could send 3 datagram packets in order from the server, yet the client may get them in a different order (2,1,3). Or it may not get one of them at all, in which case you either want it resent (doubtful) or simply ignore it and move on at some timeout.
Look into using Real Time Protocol RFC3550 (http://en.wikipedia.org/wiki/Real-time_Transport_Protocol)
as the transport over UDP. RTCP as the control over TCP.
Related
I'm building a proxy with two endpoints and with a custom protocol in between.
Means, I'll receive the original request on one site, serialize it for the custom protocol, de-serialize it on the other end and send it to a defined target server. Same back with the response.
The thing looks about like this:
This all works wonderful. The thing is, that the custom protocol in the middle has a max size of about 5 MB. Although I need to be able to post files bigger than this.
I now had an idea, which I'm not sure if it is possible and I would be very happy about some advice.
Right now, I'm collecting all the HttpObjects and send the whole request at once over the custom protocol. On the other end, I'm parsing a FullHttpRequest, modify the Host, URI and so one and send it to the target server. Here again, same procedure with the response. This is of course a waste of memory and time.
Now with this I'm not sure:
I could immediately send all the HttpObjects that I receive, over the custom protocol without collecting the whole request first and send it in a whole.
On the other end, I still could manipulate the one HttpRequest object and the just pump all the HttpObjects, one after the other, into the outgoing channel until the HttpLastContent object. Would this work?
I thought I'd rather ask first, before putting too much effort in it just to find out it's a stupid idea.
I am trying to implement a client-server in java
and i made connection between in sockets
and sending JSON objects as strings on streams
if i have big object is there's a way to handle it
so i don't have to regroup it because the limit size of tcp packet (cant know when the single object is fully transferred to me as client or not yet)
note :am using G-son to convert objects to JSON objects
If I have big object is there's a way to handle it so I don't have to regroup it because the limit size of tcp packet. (I cant know when the single object is fully transferred to me as client or not yet)
Actually, the client can know when it has received a complete JSON object. When your client sees the } that matches the opening {, you have the complete object. Of course, this means that that your client needs to understand JSON syntax, but you can use an off-the-shelf JSON parser to do that.
So the best way to do this is for the server to generate and send the JSON, and the client to parse the socket input stream using a normal JSON parser. If you do it that way, then you don't need to know whether the TCP/IP stack has broken the data stream into multiple packets. By the time the JSON parser sees them, they will have been reassembled into a stream of bytes.
If this doesn't answer your question, we need to see what your code is currently doing to generate and send the JSON on the server side.
is there's a way to handle it so i don't have to regroup it because the limit size of tcp packet
You don't have to care about the size of TCP packets. Just write the data. TCP will segmentize and packetize it for you.
(cant know when the single object is fully transferred to me as client or not yet)
Yes you can. You reach the closing '}', as #StephenC mentions. Your JSON parser should take of that for you in any case.
Your question is founded on false assumptions.
This may be a "newb" question but here it goes anyway. We have a netty server up and running and we want it to support multiple different protocols like straight tcp, http, udp etc.. I am trying to write a class to be more dynamic what handlers/decoders/encoders we add to the pipeline on every request so we only add the layers we need depending on what type of traffic it is. I've got straight tcp figured out because we are encoding special bytes but I'm having a hard time coming up with a clever way to tell if its HTTP traffic vs straight tcp based off a ChannelBuffer or byte array.
My thoughts have been along the line of reading in some bytes and looking for a string like 'GET' or 'POST', I assume a HTTPRequest would have these items somewhere.. Is what I'm trying to do worth it? Or anyone have any helpful ideas?
I think you want to have a look at the portunification example where we do something like what you want to do. In short it's possible to do what you want. For more infos and more details please check the example at [1].
[1.a (master_deprecated)] https://github.com/netty/netty/blob/master_deprecated/example/src/main/java/io/netty/example/portunification/PortUnificationServerHandler.java
[1.b (4.1)] https://github.com/netty/netty/blob/4.1/example/src/main/java/io/netty/example/portunification/PortUnificationServerHandler.java
I am a novice programmer in java.
I have created a program which is similar to a chat application using socket programming.
I haven't used threads.
My question is:
Whenever a client1 wants to communicate to another client2 via the sever how can i know which client is communicating.
I thought if i could differentiate all clients from server side by using sessions it would be easier. Just a random thought.
why this question??
I want to know this because i have stored the adressess of clients in a file along with a sequence number to make the messages visible to the pair alone globally. Whenever a client sends a message it prefixes it with a sequence number which is got from the client1 client2 pair stored in that file.
Any help would be greatly appreciated. Im just a learner in java. I apologize for any obscurity in my question.
First of all, try to make a thread to open a socket because it helps in your GUI processing. And the point that you want to see client names can be done by this steps:-
Add an editbox and enter your name (client name) and send this name along with the message and at server-side, split message and name so that you can determine which message is sent by whom.
Ex:- Client name is Alex and the message is "hi" then the data which will be sent is something like "Alex+hi". Now split this message using split() function in java at the server-side.
Hope this encoding and decoding will help you.
Am developing one java application using netty .In this application it will read data from the device and put it into database .But here the problem is once the device send half data it will read and again the device is sending half data . In threads Thread.sleep() method is there to wait for complete data . In Netty am using Non Blocking Ios(NIO). Please tell me how to wait NIOs to read complete data.
Thanks
You will need to implement your own FrameDecoder which makes sure that the ChannelBuffer will only get based to your business handler once it is complete.
See [1].
[1] https://netty.io/3.9/api/org/jboss/netty/handler/codec/frame/FrameDecoder.html
You can simply use ReplayingDecoder, which will read until data is complete.
Here you can take a look for example.