Author
J2Me datagram connection with multicast socket server
eric jackson
Greenhorn
Joined: Feb 03, 2005
Posts: 3
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
Joined: Feb 05, 2001
Posts: 17224
posted Feb 04, 2005 16:32:00
0
"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
Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
subject: J2Me datagram connection with multicast socket server