Convert SDP data from byte[] into Object? - java

I am currently sending and receiving SIP messages across a network.
When I want to add SDP data to a SIP message I use the SessionDescription object in jrtp.
This object is then added to the SIP message.
But when I get a SIP message from the server its SDP is in a byte[] array.
So I'm wondering is there anyway to convert the byte[] back into a SessionDescription object so I can use the SessionDescription object's methods to parse the data?

I think you can use Byte[] wrapper class of byte.

Related

How to encrypt java object and send it as String in URL?

I have a Java object in which I have product information. This information I want to send to controller in URL using Get method. I want to send this object as encrypted string format.In the controller I want to decrypt information and get the values from the object. Or is there any other way to do so?

How to get the Jgroups Message object content as string

I'm using jgroups for cluster node communication. I'm sending messages using channel, but unable to get the received message content. Used msg.getBuffer() and msg.getRawBuffer() methods, but after converting into string getting SOH SOH in the outpout. I just want only the message content not the 'src' or 'dest' hosts. How to get that from Message object?
If you use a string as payload, I suggest either
Set the contents using msg.setObject("hello world") and msg.getObject(), which returns the string "hello world"
OR
Set the contents using msg.setBuffer("hello world".getBytes()) and new String(msg.getRawBuffer(), msg.getOffset(), msg.getLength()).
In the first case, you use a helper method of JGroups to set and retrieve the object, in the latter case you do the (de-)serialization yourself.

Web Socket - Spring : Confirm of message received

I am sending a message through WebSocket with Spring from Tomcat Server to a SockJSClient with the method:
WebSocketSession.sendMessage(WebSocketMessage<?> message)
and I would like to know when the message has been received (eventually with complementary information, for example whether the logic on client successfully processed), then go for next message.
This is an Activity diagram that explains the use case.
How can I receive confirmation of reception or result from client?
As Erwin pointed, you can adopt some higher protocol providing such feature like STOMP. However, if you are afraid to adopt it only for that feature, you can implement that feature by yourself.
The first thing is to give each message id to identify each message, type to recognize the purpose of each message, data to transport a message's content and reply which is a flag to see whether or not ACK is required and to use a format like JSON to serialize/deserialize an object containing these data into/from WebSocket message.
When sending a message, it creates an object by issuing a new id for that message, setting type to message and data to given message and reply to true if ACK is required or false if not. And it serializes it into JSON and sends it as a WebSocket message. - https://github.com/cettia/cettia-protocol/blob/1.0.0-Alpha1/lib/server.js#L88-L110
When receiving a message, it deserializes JSON to the above object. If reply is true, it sends a special message whose type is reply setting data to id of that message. Then, the counterpart can confirm that its counterpart has received a message whose id is id. - https://github.com/cettia/cettia-protocol/blob/1.0.0-Alpha1/lib/server.js#L46-L76
The above links point similar implementation in Cettia which is a real-time web application framework I wrote. Though that implementation is a little bit complex as it is designed to allow for user to handle callbacks with result, you are likely to get the basic idea.
API implemented by that link looks like the following.
A server or client which requires a result of event processing.
// Using Java server with lambda
socket.send("foo", "bar", result -> /* resolved */, reason -> /* rejected */);
The corresponding client or server which has a responsibility to submit the result.
// Using JavaScript client with arrow functions
socket.on("foo", (data, reply) => {
// data is 'bar'
// 'reply.resolve(result)' if it successes
// 'reply.reject(reason)' if it fails
});

how to create SIP uri using java.net.URI class?

The server or you can say VOIP provider is ekiga.net.
I want to call this contact sip:500#ekiga.net. I have created sip headers as defined in rfc3261 and I want to create a sip uri using URI class. This is what I need help with.
The Purpose for creating uri is to send the udp packet that contains sip headers and messages to the server. I don't know what address to use because DataGram class needs destination ip and port. I know the port is 5060 but I don't know which url to use.
Thanks
Java don't have built-in support for SIP, so you don't need java for SIP URI.
Optionally first you might perform a DNS lookup like this:
InetAddress inetAddress = InetAddress.getByName("ekiga.net");
(this will lookup A record only. For VoIP you should use SRV DNS records, but that requires a seprate lib and A record is usually just fine)
Then create an UDP socket like this:
DatagramSocket socket = new DatagramSocket();
Then send any message like this (buff must hold a valid SIP message):
socket.send(new DatagramPacket(buf, buf.length, InetAddress.getByName("ekigaaddresshere"), 5060));
Then read the answer(s) and send other requests.

Encoding and Decoding of Pcap Packets

I need to convert packets to byte format and decode it . How is it possible to convert packets captured using jnetpcap library to array[bytes] and vice-versa in Java?
PcapPacket class has the method
public int transferStateAndDataTo(byte[] buffer) which will copy the contents of the packet to the byte array.
define the byte[] with size as packet.getTotalSize()
if you are looking for the payload
//opens an offline pcap file
Pcap pcap = Pcap.openOffline(pcapIpFile, errbuf);
//packet object
PcapPacket packet = new PcapPacket(JMemory.POINTER);
Payload pl = new Payload();
pcap.nextEx(packet); // retrieves the next packet from input loop thru until eof
if(packet.hasHeader(pl)) //this will check for and retrieve the payload
pl.data() // this will give you the data in the payload as a byte stream
for data in the different headers (ethernet/ip/tcp) there are other methods available with the implementation

Categories

Resources