Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
ricos
Posts: 48
Registered: ‎06-08-2009
My Device: Bold 9000

Changing destination on UDP socket?

Hello,

 

I need to change the destination address (IP and port) of sending datagram on UDP socket that is already created.

To do it, I used Datagram.setAddress() function.

But when I send this datagram, send() function throws ClassCastException.

Here is my code:

 

	public void init(String ip, int port)
	{
		String url = "udp://" + ip + ":" + port + "/;deviceside=true";

		try {
			m_rtpSock = (UDPDatagramConnection) Connector.open(url);
		} catch (IOException e) {
			
		}

		if (m_rtpSock != null) {
			try {
				m_sendDgram = m_rtpSock.newDatagram(1024);
			} catch (IOException e) {
				m_rtpSock = null;
			}
		}

		return;
	}

	public int sendData(String newIP, int newPort, byte[] bytes, int len) {
		try {
			m_sendDgram.reset();
			m_sendDgram.setData(bytes, 0, len);
			m_sendDgram.setAddress("//" + newIP + ":" + newPort);

			m_rtpSock.send(m_sendDgram);
		} catch (IOException e) {
			return 0;
		}

		return 1;

	}

 How can I change the destination address of UDP datagram wihtout creating new socket?

Or, Is it impossible?

 

Regards,

Ricos.

 

New Developer
ricos
Posts: 48
Registered: ‎06-08-2009
My Device: Bold 9000

Re: Changing destination on UDP socket?

Hi, gurus. Please help me. Really, is it impossible?
New Contributor
iceczd
Posts: 9
Registered: ‎03-30-2011
My Device: Bold 9700

Re: Changing destination on UDP socket?

This technique works on some devices like my 9700 but not my 8320.
RIM fails to address the issue.