Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

J2Me datagram connection with multicast socket server

 
eric jackson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , i am creating a pda client with datagram connection (for receiving information only) to be connected to a Udp server with multi-cast ip address and port number. Is it possible to connect between a datagram connection(J2ME UDP) to a J2SE(udp multicast socket connection) ?

below is the pda client connection

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
import java.util.*;

public class testPDA extends MIDlet implements CommandListener
{
private Command exitCommand,nextCommand;
private Display display;
private Form screen;
private StringItem nameItem;
private Vector client1;
private Datagram receiveDatagram;
//private DatagramClientHandler client;
private DatagramConnection dc;

public testPDA()
{
display = Display.getDisplay(this);

exitCommand= new Command("Exit", Command.EXIT,2);
nextCommand = new Command("Next",Command.OK, 2);

screen = new Form("Welcome to Pda");
nameItem= new StringItem("" , "Retrieving info..");
screen.append(nameItem);

client1 = new Vector();

}

public void startApp() throws MIDletStateChangeException
{
try
{
display.setCurrent(screen);
connect();

}
catch(Exception o)
{

}
}

public void pauseApp()
{

}

public void destroyApp(boolean con)
{
}


public void commandAction(Command c, Displayable s)
{
if(c == exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
else if(c==nextCommand)
{
try
{
connect();
}
catch(Exception e)
{
}

}
}

private void connect() throws Exception
{

try
{
dc = (DatagramConnection)
Connector.open("datagram://230.0.0.1:9000");


receiveDatagram = dc.newDatagram(dc.getMaximumLength());

String retval="";

try
{
dc.receive(receiveDatagram);
byte[] data = receiveDatagram.getData();

retval = new String
(data,0,receiveDatagram.getLength());




}




catch(IOException oe)
{
System.out.println(oe.toString());
}








}
catch(Exception e)
{
e.printStackTrace();
}

finally
{
dc.close();
}

}

}
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Jackson Jackson"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic