Implementing sockets and threads in a jframe gui program

Hi, I am trying to find a solution to a problem I am having designing my instant messenger application.
I am creating listening sockets and threads for each client logged into the system. i want to know if there is a way to listen to other clients request from the main gui and then if another client tries to establish a connection with me for example, a thread is created for that client and then my chat gui opens automatically has soon has the other client sends his or hers first text message to me.
I am relatively new at socket programming has I am currently studying along this area. I know how to create threads and sockets but I am having trouble finding out a solution to my problem. Here is the code that I have done so far for the listening method from my main gui, and the thread class of what I have done so far.
listening socket:
     private void listeningSocket()
            ServerSocket serverSocket = null;
            boolean listening = true;
            try
                //listen in port 4444;
                serverSocket = new ServerSocket(4444);
            catch(IOException x)
                JOptionPane.showMessageDialog(null, "cannot listen to port 4444", null, JOptionPane.ERROR_MESSAGE);
            while(listening)
                client_thread w;
                try
                   w = new client_thread(serverSocket.accept(), jTextArea1);
                   Thread t = new Thread(w);
                   t.start();
                catch(IOException x)
                     JOptionPane.showMessageDialog(null, "error, cannot start new thread", null, JOptionPane.ERROR_MESSAGE);
        }thread class:
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
* @author jonathan
public class client_thread extends Thread
     //define new socket object
    private Socket client_user = null;
    private JTextArea textArea;
    public client_thread(Socket client_user, JTextArea textArea)
        this.client_user = client_user;
        this.textArea = textArea;
    public void run()
        BufferedReader in = null;
        PrintWriter out = null;
        String error = "error has occured, messege was not sent";
        String messege = null;
         try
            //create input and output streams
            in = new BufferedReader(new InputStreamReader (client_user.getInputStream()));
            out = new PrintWriter(client_user.getOutputStream(), true);
            while(true)
               //read messege sent by user
               messege = in.readLine();
                //display messege in textfield
               out.println(messege);
               textArea.append(messege);
        catch (IOException e)
            //error messege
            JOptionPane.showMessageDialog(null, error, null, JOptionPane.ERROR_MESSAGE);
}

Seems like all you need to do is create a new dialog for each socket that is established. Your current design looks like it will attempt to use the same textarea for all the sockets.
I would say in your thread class do the following:
MyConversationDialog dialog = new MyConversationDialog();
while(true)
               //read messege sent by user
               messege = in.readLine();
                //display messege in textfield
               out.println(messege);
               dialog.setVisible (true);
               dialog.addMessage (message);
            }

Similar Messages

  • Sockets and thread communication multiplexing?

    Hello,
    I need to implement a server which will have a maximum of 10 clients connected.
    I wanted to go for classic blocking I/O because I won't have much clients.
    My problem is that even if I accept() some sockets and then create a thread for each socket,
    then I still need to communicate some data to the other threads, problem is that I am blocked
    on the read() operation, how could I address this problem?
    I mean, lets say I am thread1 and blocked on read() on my socket, now thread7 wants to tell
    me something like a chat message coming from client he handles, how could thread7 manage
    to wake thread1 and send him a message somehow?
    I do not want to deal with NIO stuff if possible because I do not need to scale, I just have a
    problem because I am stuck on the read.
    I will run on Windows.
    Thanks for help.
    Edited by: Marzullo on Jul 15, 2010 1:05 PM

    Fully answered in [your other thread|http://forums.sun.com/thread.jspa?threadID=5445070&messageID=11020688#11020688].
    Please don't multipost, as it can lead to people wasting their time repeating others' answers.

  • Socket and Thread Explanation

    I'm a little confused on the Socket stuff. I read some tutorials but wanted to make sure I understand. I'm using a simple client/server chat app as a reference.
    First the ServerSocket is just a connection to the port you want to listen on... I understand that. Is the Sockets... Socket s = ss.accept(); a tunnel to the port for data to travel on?
    Second.. When you create a Thread. This is the information that travels on these sockets? If that's the case I understand... But I have one question relating to some chat code I can't quite figure out.
    The simple chat program conists of a ChatServer, ServerThread and a Client.
    in the ChatServer it creates a ServerSocket and later on it looks for new connections for clients and then creates a ServerThread. What the heck is this for. From the code in the ServerThread it just handles incoming data and sends them back out. OK.
    But in the Client... it connects to this port and then creates it's own thread i.e. new Thread(this).start();
    Why ServerThread and then a Thread from the Client... Shouldn't there just be one?
    Sorry, I just can't get this.

    I'm a little confused on the Socket stuff. I read
    some tutorials but wanted to make sure I understand.
    I'm using a simple client/server chat app as a
    reference.
    First the ServerSocket is just a connection to the
    port you want to listen on... I understand that. Is
    the Sockets... Socket s = ss.accept(); a tunnel to
    the port for data to travel on?when the accept() method called, the server socket will start listening to the port for any connection. Once a connection established, this method will return a connected socket.
    >
    Second.. When you create a Thread. This is the
    information that travels on these sockets? If that's
    the case I understand... But I have one question
    relating to some chat code I can't quite figure out.A new thread was created here to that this thread can handle the socket return by the serversocket independenty to the main thread. Mainly server code will do this so that the main thread can continue to listening to other new connection agains while this newly created thread will handle any communication between a connected client and server.
    The simple chat program conists of a ChatServer,
    ServerThread and a Client.
    in the ChatServer it creates a ServerSocket and later
    on it looks for new connections for clients and then
    creates a ServerThread. What the heck is this for.
    From the code in the ServerThread it just handles
    incoming data and sends them back out. OK.
    But in the Client... it connects to this port and then
    creates it's own thread i.e. new Thread(this).start();Well, i dun know how the code for the client look like... but guessing that the client was implements Runnable. So, in the main method, it spawn a new thread and pass this class for this new thread to handle while the main thread maybe continue to do other things or just end after finish.
    >
    Why ServerThread and then a Thread from the Client...
    Shouldn't there just be one?
    Sorry, I just can't get this.Well, hope my explaination was clear enough... :P

  • Problem with socket and Threads

    Hi,
    I have coded a package that sends an sms via a gateway.
    Here is what is happening:
    * I create a singleton of my SMSModule.
    * I create an sms object.
    * I put the object in a Queue.
    * I start a new Thread in my sms module that reads sms from queue.
    * I connect to sms gateway.
    * I send the sms.
    * I disconnect from socket! This is where things go wrong and I get the following error (see below).
    I have a zip file with the code so if you have time to take a look at it I would appreciate it.
    Anyway all hints are appreciated!
    //Mikael
    GOT: !LogoffConf:
    mSIP Kommando var: !LogoffConf
    CoolFlix log: MSIPProtocolHandler;setLoggedin(false)
    We got LogOffConf
    Waiting ......for thread to die
    java.net.SocketException: Socket operation on nonsocket: JVM_recv in
    socket input stream read
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:116)
    at
    sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:405)

    Off the top of my head, probably the garbage collector cleared your SMSModule coz all classes loaded through other classloaders will be unloaded when that classloader is unloaded.
    mail in the code if you want me to look at it with greater detail.

  • Socket and threads.

    I have written a socket client and a socket server. The client sends a directory name and the server sends directory files and their content. The client asks for files every five seconds (it has to be made once every day, but for trials I have reduced the time), so I have written a thread to made the client sleep for that time. The problem appears after looping fifty or sixty times, when the socket, which does not die, stops making its work (files are not send any more). I really thank every answer.

    Please be clear. What "stops work" the client or the server? Can you post the relevant code that is "looping fifty or sixty times"?

  • Socket and Thread fun

    I am currently playing around with a, MUD like, program.
    I have 2 classes, server class who's main function is to listen to the port and create a new client class with the value of the incomming socket.
    The client class extends Thread, and pretty much just processes the input from the client socket.
    Now this is all good until I wanted to have multiple clients and have them talking to each other. I thought that having a Vector and storing the sockets in another class was the way to go. But whenever I refer to Vectors and Sockets I get the following runtime error :
    java.lang.NullPointerException
    at Controller.addSocket(ClientConnection.java:62)
    at ClientConnection.run(ClientConnection.java:35)
    Where line 35 is sending the socket to the class that adds it to the Vector, and 62 is trying to add the Socket to Vector.
    What am I doing wrong? Is there a better way of doing it, and if so a link to an example would be good.
    Cheers
    Shane

    From the stack traces, it is saying that the Controller is a null object. Probably you forgot to call on new Vector(), or you declared it twice in the constructor. There could also be a possibility that the socket passed to it was null.

  • Socket and Thread Question?

    I have a Server/Client app where the Client connects to the server and the server accepts the Client and starts a new thread for each client.
    Then the Server Thread waits for the Client to contact.
    I set the timeout on the Server socket to 30 seconds.
    but the Client could sit there idle for much longer.
    So on the client side i used a timer to send "-1" every 5 seconds.
    That way if the Server Thread times out i know the Client is not there and end the thread and close everything.
    Now on the client side i may send several strings in a row to the server so i do not want my "-1" timer (i'm still here) messages to get intermingled with regular Client messages so i set up a boolean variable like so:
        volatile private boolean out1busy = false;
        private synchronized boolean getOut1busy(){
         return out1busy;
        private synchronized void setOut1busy(boolean on){
         out1busy = on;
        }then before using the socket i do this:
            while (getOut1busy()) try { Thread.sleep(40); } catch (InterruptedException ex) {}
            setOut1busy(true);
            lobbyOut.println("-1");
            setOut1busy(false);I have been running this for over a year and have personally never had a problem but have had rare clients testing say their comp has suddenly bogged down and it seems like they are describing what might happen if Out1Busy is set to true and not set back to false.
    ive checked my code and like i say it has never happened to me BUT i feel like what i am doing here is not the right way and there is probably a much better way to accomplish this. It is the only place in my code i see the chance of an infinate loop occuring.
    So regardless of whether or not it is even causing a problem can anyone tell me if it might cause a problem and a better way to do it.

    how about this.
    everywhere that i send data to the server that is not already on the event dispatch thread i just put in an invoke later which wold execute it on the eventdispatch thread.
    that way all communication with the server would be done on the event dispatch thread.
    so if i click a button that sends several strings right in a row it would complete before the "-1" im still here message sent at the same time goes through.
    so even if i had two bits of code that send several strings that need to be received in a row they would not get intermingled as long as they were both executed within a invokelater or already executed on the event dispatch thread (like a mouse clicked or action performed)
    so in my case here i always contact the server in either a state changed, action performed, or mouseclicked except for the "-1" im still here message.
    are alll these (state changed, action performed, or mouseclicked) executed on the event dispatch thread?
    i just put the "-1" in an invoke later and take out all the sleep and outbusy variable stuff.

  • Socket and Thread Problem

    When reading an Inputstream received after a connection has been established (throught a Socke connect) between a Server ands a Client , messages are being lost when a wait method is call. A client sents message which have to be processed and response sent back to the client . The message are encoded and as the code below shows each message ends with a '":" .Not only one message is sent at a time. and when messages are sent the client sometimes expect replies. This means that when a message is read , it be being processed by a Processor and until the reply has be sent this the thread reading the messages has to wait. when a reply is sent and the thread is waken up, the remaining the messages in the Input stream gets lost but the loop is not also exited since the end of the file is never reached.
    Solution:
    1. read a command message. if you find end of message, process the message and wait until you are notify and continue with the next command line
    public class Sender extends Thread {
         private Socket socket;
         private Processor processor = newProcessor();
         private boolean DEBUG = false;
         public Sender (Socket socket) {
              super();
              this.socket = socket;
              start();
         public void run() {
              while (true) {
                   if (processor .getStateOfProcess()&& socket != null) {
                        InputStream input = null;
                        try {
                             input = socket.getInputStream();
                             if (processor .dispatchMessage() != null) {
                                  socket.getOutputStream().write(
                                            CacheManager.dispatchMessage());
                                  processor .ClearMessage();
                        } catch (IOException ex) {
                        int i = 0;
                        char oldChar = ' ';
                        char c = ' ';
                        StringBuffer buffer = new StringBuffer();
                        try {
                             while ((i = input .read()) != -1) {
                                  c = (char) i;
                                  buffer.append(c);
                                                    if (c == ':' && oldChar != '\\') {
                                       processor .process(buffer.toString());
                                       buffer = new StringBuffer();
                                       c = ' ';
                                                              try {
                                            synchronized (this) {
                                                 wait();                         
                                       } catch (InterruptedException e1) {
                                                       if (processor.dispatchMessage() != null) {
                                            socket.getOutputStream().write(
                                                      CacheManager.dispatchMessage());
                                            processor.ClearMessage();
                                  oldChar = c;
                                    } catch (IOException e) {
       public void wakeup() {
              synchronized (this) {
                   notify();
    } This thread leaves that wait when the wakeup method is called in the Processor class.
    Question
    can some one help me figure out way and where the messages are being lost after the first message has been processed. why can the other message not be seen even other messages are still sent.
    What can be a possible solution
    thanks

    I didn't follow all of that, but I can see one serious error in your concurrent. You should always test the condition you're waiting for inside the synchronized block - otherwise you can't be certain that wait() is called before the corresponding notify() / notifyAll() call.

  • Multi channel design issue - sockets and threads

    How are multiple channels handled in a chat program? Does the server separate the channels by having a port open for each channel, or is it done some other way?
    Thanks

    Yes it is possible. A user is logged on as long as the applet has a socket connection that has passed the login phase.
    Keep a server on the web site that handles the chat stuff. If you want to show some statistics like the users logged on, you can access the server from your local web site and ask him what's going on.
    You can do this with an administrative command set (your statistics module has to login to the server just like a chatter), with a special tcp port or with thread communication. In the latter case server and servlet would have to reside in the same JVM which is not really trivial...
    Another approach is to write the statistics into a shared file, and read this file from your web server.
    -- Stephan

  • Timer, socket, and thread

    I need to write a code that will open and write on/to a socket in less than two minutes. what classes should i have? I know I need the timer and socket, but which one should i use first? open a socket first than create a timer, or the other way? I'm new to this all OO stuff

    I need to write a code that will open and write on/to
    a socket in less than two minutes. ???
    what classes
    should i have? I know I need the timer and socket,
    but which one should i use first? open a socket first
    than create a timer, or the other way? I'm new to
    this all OO stuffhttp://java.sun.com/docs/books/tutorial/
    http://java.sun.com/docs/books/tutorial/essential/concurrency/
    http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Tech/Chapter08/timers.html
    http://java.sun.com/docs/books/tutorial/networking/sockets/index.html

  • Socket and Thread

    Hi,
    I am debugging a solution which had a filesend
    and dolisten method in the workchat project
    client: Project WorkChat
    https://docs.google.com/uc?authuser=0&id=0B3IOYEdd-pYSWVVtRzNHTGsxSjQ&export=download
    run the server before running this project
    and change the ip in the config point it to the server
    Also press enter in the right-top text box after typing the username,to start chat
    Double click to open private chat with another user.
    Drag and drop on user to send file
    server:
    https://drive.google.com/uc?authuser=0&id=0B3IOYEdd-pYSRjFyY0tKNmQ1bGc&export=download
    It is tough to test this solution and repair its filesend feature..
    Somehow it did work ,,but something went wrong of missing..
    I want to debug it and know what's not working in the filesend/dolisten methods.
    The rest of the code was derived from a vbsocket library which may now be unavailable through the MSDN
    Regards.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help , or you may vote-up a helpful post

    Hello,
    I agree with Eason - you'd need to ask Google for help.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog:http://unlockpowershell.wordpress.com
    My Book:Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C40686F746D61696C2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • How to start a Web GUI program from a Web Dynpro application

    I know the program name , and it is a Web GUI program ,is anybody know how to start it from a Web Dynpro application

    hi,
    I use the following program to call a SAP GUI program :
    DATA: l_componentcontroller TYPE REF TO ig_componentcontroller.
      DATA: l_api_componentcontroller type ref to if_wd_component.
      DATA: l_sapgui_manager type ref to cl_wdr_sapgui_integration.
      DATA: lt_parameters    TYPE wdr_name_value_list.
      l_componentcontroller = wd_this->get_componentcontroller_ctr( ).
      l_api_componentcontroller = l_componentcontroller->wd_get_api( ).
      l_sapgui_manager = l_api_componentcontroller->get_sapgui_manager( ).
      IF l_sapgui_manager IS NOT INITIAL.
        l_sapgui_manager->fire( EXPORTING name = 'PROGRAM_NAME 'parameters = lt_parameters ).
    But the l_sapgui_manager is always initial , what can I do ?
    ENDIF.

  • Creating a java thread in a jframe class?

    hello is this possible to create a thread for a jframe class? so that everytime a connection is established, a new thread along with the gui is opened automaticly? if so, would i just need to insert extends Thread on my declaration of my class?
    i already have this code at the top of my jframe class..
    public class ChatDialog extends javax.swing.JFrame implements WindowListenerwhere and how would i implement the run() method in thsi class?
    full code:
    package icomm;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class ChatDialog extends javax.swing.JFrame implements WindowListener {
        protected String messege;
        private Socket client_user = null;
        /** Creates new form ChatDialog */
        public ChatDialog()
            initComponents();
            addWindowListener( this );
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            convo_txt = new javax.swing.JTextArea();
            jScrollPane2 = new javax.swing.JScrollPane();
            txt_messege = new javax.swing.JTextArea();
            send_button = new javax.swing.JButton();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            Option = new javax.swing.JMenu();
            getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            jScrollPane1.setViewportView(convo_txt);
            getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 220, 270));
            jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            txt_messege.setLineWrap(true);
            jScrollPane2.setViewportView(txt_messege);
            getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 310, 220, 70));
            send_button.setText("Send");
            send_button.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    send_buttonActionPerformed(evt);
            getContentPane().add(send_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 390, -1, -1));
            jMenu1.setText("File");
            jMenuBar1.add(jMenu1);
            Option.setText("Option");
            jMenuBar1.add(Option);
            setJMenuBar(jMenuBar1);
            pack();
        // </editor-fold>
        private void send_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                           
            //get txt from textbox   
            String text = txt_messege.getText();
        public void windowClosing(WindowEvent e)
            public void windowActivated(WindowEvent e) {}
         public void windowClosed(WindowEvent e) {}
         public void windowDeactivated(WindowEvent e) {}
         public void windowDeiconified(WindowEvent e) {}
         public void windowIconified(WindowEvent e) {}
          public void windowOpened(WindowEvent e)
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new ChatDialog().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JMenu Option;
        private javax.swing.JTextArea convo_txt;
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JButton send_button;
        private javax.swing.JTextArea txt_messege;
        // End of variables declaration
    }

    Instead of attempting to have the frame extend thread (or implement Runnable which is actually possible since you cannot have multiple inferitance). You might want to just create the frame and have that frame lauch an associated thread to take care of the processing required.

  • Socket and ObjectOutputStream

    I created an ObjectOutputStream from a socket.
    ObjectOutputStream out=new ObjectOutputStream(s.getOutputStream());
    Is there any way to get the socket from this object sream?

    I agree with u. And also i dont really need the socket once i have created objectstreams from it.
    I have a ServerSocket which creates a socket the moment someone connects to it. From that socket I am creating object streams. After creating the streams I am passing on the values of the streams(both in and out) to a JFrame object which also implements Runnable. The problem is that my in stream is working here but not my out.
    But the in and out works in the calling method. So I wanted to find out what is the IP address to which my OUT in the thread is sending the object.

  • Conflict between socket and RMI

    Hi
    I wrote a program in client-server using socket and it was fine. I also wrote a client-server program using RMI. Fine as well. But after I connected the client-server using socket (open socket, send-receive messages, close socket), then use RMI. I got java.rmi.NotBoundException.
    Would anyone have a look and provide your feedback please? Thanks.
    big J
    *****************this is Server.java ***************************
    package single;
    import java.io.*;
    import java.rmi.Naming;
    import java.rmi.RemoteException;
    import java.net.*;
    import java.rmi.*;
    public class Server
    extends Thread {
    public static final int SOCKETPORT = 5555;
    private String serverName;
    public Server() throws IOException {
    System.out.println("*** socket opened ***");
    serverName = new String("localhost");
    ServerSocket serverSocket = new ServerSocket(SOCKETPORT);
    Socket socket = serverSocket.accept();
    InputStream is = socket.getInputStream();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
    System.out.println(bufferedReader.readLine());
    OutputStream os = socket.getOutputStream();
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os), true);
    printWriter.println("from server");
    os.close();
    is.close();
    socket.close();
    System.out.println("*** socket closed ***");
    public void runServer() {
    System.out.println("*** start of run():RMI ***");
    System.setSecurityManager(new SecurityManager());
    try {
    RMIInterfaceImpl rMIInterfaceImpl = new RMIInterfaceImpl();
    Naming.bind("//" + serverName + ":9999/RMIInterface", rMIInterfaceImpl);
    catch (RemoteException ex) {
    catch (MalformedURLException ex) {
    catch (AlreadyBoundException ex) {
    System.out.println("*** end of run():RMI ***");
    public static void main(String args[]) throws Exception {
    Server server = new Server();
    server.runServer();
    ******************this is Client.java **************************
    package single;
    import java.io.*;
    import java.net.*;
    import java.rmi.Naming;
    public class Client {
    private String serverName;
    private final static int SOCKETPORT = 5555;
    public Client() throws IOException {
    serverName = new String("localhost");
    Socket socket = new Socket(serverName, SOCKETPORT);
    OutputStream os = socket.getOutputStream();
    PrintWriter printWriter=new PrintWriter(os, true);
    printWriter.println("from client");
    InputStream is = socket.getInputStream();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
    System.out.println(bufferedReader.readLine());
    is.close();
    os.close();
    socket.close();
    public void runClient() throws Exception {
    System.out.println("*** start of runClient():RMI ***");
    System.setSecurityManager(new SecurityManager());
    RMIInterface rMIInterfaceImpl = (RMIInterface) Naming.lookup(
    "//" + serverName + ":9999/RMIInterface");
    String str = rMIInterfaceImpl.print();
    System.out.println(str);
    rMIInterfaceImpl.serverSide();
    System.out.println("*** end of runClient():RMI ***");
    public static void main(String args[]) throws Exception {
    Client client = new Client();
    client.runClient();
    ***************** this is RMIInterface.java ***********************
    package single;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    interface RMIInterface
    extends Remote {
    String print() throws RemoteException;
    void serverSide() throws RemoteException;
    ********************* this is RMIInterfaceImpl.java ***************
    package single;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    public class RMIInterfaceImpl
    extends UnicastRemoteObject
    implements RMIInterface {
    public RMIInterfaceImpl() throws RemoteException {}
    public String print() {
    return new String("hello world");
    public void serverSide(){
    System.out.println("this should appear in serverside");

    I think you have a timing problem between your client and server. As soon as your client and server programs have finished their socket communication, they will both do their "runServer"/"runClient" methods. If the client attempts to lookup the server before the server has registered itself via Naming.bind(), I would expect that's why you're getting a NotBoundException in the client.
    You probably wouldn't use the design of your test client/server for something significant, but a quick and dirty way to make this work might be to have the client call Thread.sleep() for a few seconds before trying to do the lookup.

Maybe you are looking for

  • How to get the text which was clicked in  a A href tag.

    I am displaying the names from database in a page as hyperlink. When this hyperlink is clicked I want to display the corresponding address from DB. What the problem is when the link is clicked how to get the name which is clicked. I know only to link

  • PS5 Action Keyboard Shortcuts Not Working

    PS5 Action Keyboard Shortcuts Not Working -- Running 10.6.7 on a Mac Pro. Any suggestions? I've tried restarting, changing key combinations, etc. Nothing works and I'm wasting time using my mouse... Any help is greatly appreciated. 

  • Trying to decide whether to upgrade CS3 to CS5

    I've had CS3 Design Premium for a few years but never really used it much except for Photoshop.  Now I'm starting up a blog and have been reading and learning just how useful many of the other programs could be for me, but before I put a lot of effor

  • Mac is really slow to read external drive

    hello, i have a late 2012 mac book pro and a seagate 1tb paasport external drive.when i connect my drive to my computer sometimes it takes very long to read the drive right now its going on 5+ minutes and i still cant access my info.i have tested the

  • Circuit RL

    Bonjour, Je suis débutant en labview. J'ai besoin de vos aides. J'aimerais créer un modèle du moteur à courant continu (circuit RL). Dans labview, il n'y a pas des composant R, L et le bloc intégrateur.  Est-ce qu'il est possible de créer ce modèle s