| Author |
ServerSocket not oppening
|
Mash-Hud Iqbal
Greenhorn
Joined: Dec 26, 2003
Posts: 1
|
|
Hello Everyone I am a new user working on java based TINI device. I am using a application where I am using java.net. the full source code is: import java.io.*; import java.net.*; class DataLogger extends Thread { //... ServerSocket ss=null; static final int SERVER_PORT = 5713; HumidityLogger logger; DataLogger(int samples, int delay) throws LoggingException { // Create and start the logging daemon logger = new HumidityLogger(samples, delay); logger.start(); public static void main(String[] args) { System.out.println("Starting DataLogger ..."); if (args.length != 2) { System.out.println("Usage: java DataLogger samples delay"); System.exit(1); } int samples = Integer.parseInt(args[0]); int delay = Integer.parseInt(args[1]); try { (new DataLogger(samples, delay)).start(); } catch (Exception e) { System.out.println("Error creating data logger"); e.printStackTrace(); // In case any non-daemon threads have been started // System.exit(1); } } public void run() { //int SERVER_PORT=5588; ServerSocket ss=null; try { ss = new ServerSocket(SERVER_PORT); } catch (Exception e) { System.out.println("Here is the problem"); e.printStackTrace(); System.exit(1); // Abort if we can�t create ServerSocket instance return; } Socket s = null; while (true) { try { // Wait for client connections over PPP or Ethernet s = ss.accept(); } catch (IOException ioe) { // Shut down the logging daemon //logger.stopLogging(); System.out.println("Fatal problem with server socket"); ioe.printStackTrace(); // Fall out of run method break; } // Create a new thread to handle this connection (new LogWorker(s)).start(); } } private class LogWorker extends Thread { private Socket s; private LogWorker(Socket s) { this.s = s; } public void run() { DataOutputStream dout = null; try { dout = new DataOutputStream(new BufferedOutputStream(s.getOutputStream())); logger.writeLog(dout); dout.flush(); } catch (IOException ioe) { System.out.println("I/O error writing log data"); ioe.printStackTrace(); } finally { try { s.close(); dout.close(); } catch (IOException e) {} } } } } the problem is when I run it in the ServerSocket instance "ss" is not opening. it is giving me the following error: TINI /> java DataLogger.tini 60 120 & Starting DataLogger ... TINI /> Here is the problem java.io.IOException: Unable to listen on ServerSocket No other stack trace info available. So from the error it is shown the the server socket is not listing. I have done so much research on this and seem like it is like this. Please help me out what to do regards Mash-Hud
|
 |
 |
|
|
subject: ServerSocket not oppening
|
|
|