Results 1 to 3 of 3

Thread: Example help!

  1. #1
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Unhappy Example help!

    I cannot get this socket to work:
    Java Code:
    /*
     * ServerClassApp.java
     */
    
    package serverclass;
    
    import java.awt.event.ActionEvent;
    import java.io.BufferedReader;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import org.jdesktop.application.Application;
    import org.jdesktop.application.SingleFrameApplication;
    
    /**
     * The main class of the application.
     */
    public class ServerClassApp extends SingleFrameApplication {
    
        private static void listenSocket() {
            throw new UnsupportedOperationException("Not yet implemented");
        }
    
        /**
         * At startup create and show the main frame of the application.
         */
        @Override protected void startup() {
            show(new ServerClassView(this));
        }
    
        /**
         * This method is to initialize the specified window by injecting resources.
         * Windows shown in our application come fully initialized from the GUI
         * builder, so this additional configuration is not needed.
         */
        @Override protected void configureWindow(java.awt.Window root) {
        }
    
        /**
         * A convenient static getter for the application instance.
         * @return the instance of ServerClassApp
         */
        public static ServerClassApp getApplication() {
            return Application.getInstance(ServerClassApp.class);
        }
    
        /**
         * Main method launching the application.
         */
        public static void main(String[] args) {
            launch(ServerClassApp.class, args);
        /**
         * Using socket to select what port the server will be listening to, and if not possible, print a message.
         */
          Public viod listenSocket(){
              try{
                  server = new ServerSocket (4111);
              }
              catch (IOExeption e){
                  System.out.println("Can't listen to port nr 4111");
                  System.exit(-1);
              }
        /**
         * Creates the connection between client and server class *smiley*
         */
              try{
                 client = server.accept();
             } catch (IOExeption e) {
                 System.out.println("Could not establish connection on port 4111");
                 System.exit(-1);
        /**
         * Reads the data from client
         */
             }
          try {
              in = new BufferedReader (new InputSteamReader (
                      client.getInputStrem()));
              out = new PrintWriter(client.getInputStream(),
                      true);
          } catch (IOExpection e) {
              System.out.println("Could not read message.");
              System.exit(-1);
          }
       /**
         * Loops the input stream and echo
         */
              while(true) {
              try{
                  line = in.readLine();
                  out.println(line);
              } catch (IOException e) {
                  System.out.println("Can't read input stream data");
                  System.exit(-1);
              }
          }
          }
       public void actionPreformed(ActionEvent event) {
           Object source = event.getSource();
           If(source == button){
               textArea.setText(line);
           }
       }
           }
       }
        }
    }
    Do i need to import a library or is it wrong in the code? running netbeans /Thanks

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Quote Originally Posted by santa View Post
    I cannot get this socket to work:
    What doesn't work? Compiler error? Runtime exception? Stack trace? What do you expect? What happens?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    well i have a lot of errors in Netbeans. Basically its a server class socket its supposed to listen to a port for connections but right now all code is red thats why i thought maybe i don't have the proper library for sockets?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •