Design a client-server system using java

hello every body,
I'm trying to design a client-server system using java,
it work but the Qustion is:
How can I send more than one mssg on the client side, and How can I recive more than one mssg on the client side?
I tryed this:
At client_
      System.out.println("Enter your Name:");
      BufferedReader stdIn1 = new BufferedReader(new InputStreamReader(System.in));
      String userName;
      userName=stdIn1.readLine();
      //sending message to the server
       out.println(userName);
      System.out.println("Enter your password:");
      BufferedReader stdIn2 = new BufferedReader(new InputStreamReader(System.in));
      String Passw;
      Passw=stdIn2.readLine();
      //sending message to the server
      out.println(Passw);
     BufferedReader stdIn3 = new BufferedReader(new InputStreamReader(System.in));
     String userInput;
     userInput=stdIn3.readLine();
     //sending message to the server
     out.println(userInput);
   //receiving message from the server and printing
   String revc;  
   revc=in.readLine();
   System.out.println(revc);
At server_
    //reading from a client
      inputLine = in.readLine();
      outputLine = "Reply From Server :HelloClient ";
      //sending message to a client
      out.println(outputLine+"------"+ inputLine);
i hope this is the right place for my question, and hope to get help
thanks.

Is there a reason you create a new InputStreamReader and a new BufferedReader every time you prompt for user input?
lass_987 wrote:
How can I send more than one mssg on the client sideInvokeout.println()more than once.
How can I recive more than one mssg on the client side?Invokein.readLine()again.

Similar Messages

  • Need help in desigining Client/Server Application using Java

    Hi,
    I am new to Java and no sooner that I started studing it I have been given a project - client server java Application that allows a user to do a property search based on critiras (eg location, price) and display the results. I am stuck because I don't know where I need to start. Have to use IDE (Netbeans or Eclipse) but not sure about dev frameworks.
    Can someone give me an outline of what I should do / where I should start? What will be the best solution?
    Thanks in adance

    http://java.sun.com/docs/books/tutorial/networking/index.html
    That's Sun's networking tutorial series. Live it, learn it, love it. You'll need to decide if you want to use connected sockets or datagrams. You'll need details like, can multiple clients connect simultaneously?
    The tutorials are the first step though.

  • Framework for client-server Architecture in Java !!!! With swing

    Hi,
    Considering the scenario where we are having the Client-Server application and the rich clients at the client place , based on the frames.I have though of the logic as :
    Client -----------> ClientComponentframeWorkObject(Genric Objects) ---------> reading the data from the configurable files to find where to take the user action ---------> will call the Servercomponetobject(Generic objects) can be Servlet or just a object which connects to the server(DB).I have been able to find the open-source frame work at the Apache ,all covering the server-side framework so i though of doing some work with the framework covering the client(swing) -server Archetect.Even I dont know how the existing server side framework support the swing client.
    I would appericiate if someone who had worked on the client server requirement with java , could share the knowledge about the framework being used in the existing work.
    regards
    Vicky

    Hi,
    GENERIC CLIENT COMPONENT:
    package com.nst.clientcomp;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public abstract class ClientComp extends JFrame
      protected JFrame currentframe;     
      protected JPanel  panel;
      public ClientComp()
           // To decide if the ClientComp to be Frame or the Panel.
        //panel=this;     
        //currentframe=new JFrame();
        panel=new JPanel();     
        currentframe=this;
      // Just Concentrate on the GUI , look and feel here .......And the user action will generate
      // generate the event which should call the callNextView()..The component developer have to
      // concentrate on the writing the display() and the callNextView()..
      public abstract void display() ;
      // This is the Final action.Template Pattern being Called
      public String action()
           readServerObj();
           processContent();
           display();              
           return null;
       Reading of the value object which is being Passes from the Server.As per the Design it is
       called VOFS and will be read here.Here
       1) Connect to the Server
       2) Pass the VOFC through the socket connection
       3) Also obtain the VOFS(Value object from server) 
       In certain application it can be implemented here
      public Object readServerObj()
            System.out.println("Hello from ServerObj!!! Should be implemented ");
            return null;
       Processing the Sever Value Object, which is basically as VOFS.It is processed by the
       Client.And infact the Value object from Client(VOFC) should be generated here for next
       user interaction from the Client.
      public void processContent()
            System.out.println("Hello from processContent !!! Should be implemented ");
      // Clear the Frame
      private void cleanUp()
         currentframe.dispose();
         Contains the place where next view takes.Before this is invoked the cache copy of the
         StateObject should be stored in the appropriate Data Structure......      
      public void callNextView(ClientComp com)                     
            panel.removeAll();
            com.action();
            cleanUp();
    }   COMONENTS AS PER THE FRAMEWORK :
    package com.nst.clientcomp;
    import javax.swing.*;
    import java.awt.event.*;
    public class Comp1 extends ClientComp implements ActionListener
      JTextField t,t1;     
    //Default display , displaying the screen.This should be the abstract method
      public void display()
        JLabel l=new JLabel("UserName");
        t=new JTextField(10);
        JLabel l1=new JLabel("Password");
        t1=new JPasswordField(10);
        t.setText("admin");
        t1.setText("admin");
        JButton b=new JButton("Login");
        b.addActionListener(this);
           panel.add(l);
           panel.add(t);
           panel.add(l1);
           panel.add(t1);
           panel.add(b);
           currentframe.getContentPane().add(panel);
           currentframe.setSize(400,400);
           currentframe.setVisible(true);      
      public static void main(String ar[]) throws Exception     
           ClientComp c1 = (ClientComp)(Class.forName(ar[0])).newInstance();
           c1.action();             
           System.out.println("Hello11");
      public void actionPerformed(ActionEvent e)
           //Do someprocessing if required
           if(t.getText().equals("admin")&&t1.getText().equals("admin"))
           callNextView(new Comp2());  
           else
            System.out.println("invalid login");     
    } Similarly you can develop the other components and you have to take care of the display() and the user action Event which eventually calls the callNextView.I hope there might be the cases where this has been implemented ..
    Regards
    Vicky

  • Client Server program using Applets for client

    Creating a client server program using Applets for the clients.
    Having problems distrubting the message from client to client
    using ObjectOutputStreams/ObjectInputSteams.
    I can connect each client to simple server and respond with by writting
    the i/o stream of each client but unable to communicate from client to client. If any one out there has in tips of creating a class of objectOutputStreams that holds a array of ObjectOutputStreams and then broadcasts the message to every client, it would be much appreciated
    Thanks.

    Cheers poop for your reply
    I never explained the problem properly. What it is I am trying to set up a Client Server program using Applets as the clients GUI. The problem is broadcasting the message to multiply client connnection(s).
    Below is code, each client can connect and send message to the server. The problems is broadcasting the message to every client connection. The every client can input a message but only the last connected client can receive the message?????? Thanks in advance..
    /*this my server class */
    import java.io.*;
    import java.net.*;
    public class Server extends JFrame
    private static final int ServerPort=8080;
    private static final int MaxClients=10;
    private ObjectOutputStream output=null;
    private ObjectInputStream input=null;
    private BroadCastMessage broadcastMessage;
    public void runServer()          
    BroadCastMessage broadcastMessage= new BroadCastMessage();
    try
    {  //connect to server
    ServerSocket s = new ServerSocket(ServerPort,MaxClients);
         //listen to port 5000 for new connections
         ///max is 25
         System.out.println("Server listening on port "+ServerPort);
    while (state.isProgramRunning())
         try
         /// sGUI.waitForConnection();//new line
         s.setSoTimeout(100);
         //enable times in server-socket
         while (true)     
         Socket incoming = s.accept();
         //wait and accept connnections from serverSocket
         //instance of the class,pases the new connection and message
         //spawn as a thread
         SocketConnection connection=new SocketConnection(incoming,broadcastMessage);
         Thread a = new Thread(connection); a.start();
         System.out.println(state.getConnectionCount()+"Connection received from :"+incoming.getInetAddress());
         catch(InterruptedIOException x){}
    while (state.getConnectionCount()>0);
    System.exit(0);
    }catch (IOException e){}
    public static void main(String[] args)
    Server s =new Server();
         s.runServer();
    /*this is my socket connection thread*/
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    public class SocketConnection implements Runnable
    private ObjectOutputStream out;
    private ObjectOutputStream output=null;
    private ObjectInputStream input=null;
    private BroadCastMessage passOnMessage;
    private Socket theConnection=null;
    private String Inmessage="";
    private int Ocount;
    public SocketConnection(Socket caller,BroadCastMessage broadcastMessage,Ocount)
    theConnection =caller;///(5000,n)
    Ocount=ncount;
    passOnMessage=broadcastMessage;
    public void run()
    try
    getStreams();
    processConnection();
    catch(Exception e)
    {String clientDetails=("connection from IP Address: "+theConnection.getInetAddress());}
    private synchronized void getStreams() throws IOException
    { //get streams to send and receive data
    //set up output buffer to send header information
    ///Ocount++;
    //create new objectoutputstream
    output=passOnMessage.getOutputObject(output,theConnection,Ocount);
    ///flush output buffer to send header info.
    Ocount++;
    //set up input stream for objects
    input =new ObjectInputStream(
    theConnection.getInputStream());
    System.out.print("\nGot I/O streams\n");
    private synchronized void processConnection()throws IOException
    //process connection with client
    String Outmessage =" count : "+status.getConnectionCount();
    //send connection successful message to client
         Outmessage=Outmessage+"SERVER>>>Connection successful";
         output.writeObject(Outmessage);
    output.flush();
    do ///process messages sent from client
         try
         Inmessage = (String) input.readObject();
         System.out.println(Inmessage);
         /* //while the connection is open each line
         that is passed from the client to the server
         is read in and is displayed*/
         messageDetails.setMessage(Inmessage);
         String CurrentMessage=messageDetails.getMessage();
         //output.writeObject(CurrentMessage);
         // output.flush();
         passOnMessage.FloodMessage(CurrentMessage);
         //sending out the message
    catch(ClassNotFoundException classNotFoundException){}
    }while (!Outmessage.equals("CLIENT>>>TERMINATE"));
    /*this my attempt at broadcasting the message to all clients
    my thinking was that you could create a array of objectoutputstreams
    which in turn could be broadcasted(bit confussed here)*/
    import java.io.*;
    import java.net.*;
    public class BroadCastMessage /// implements Runnable
    private int count;
    private String Inmessage="";
    private ObjectOutputStream temp=null;
    private ObjectOutputStream[] output = new ObjectOutputStream [12];
    //temp level of array of objects
    public BroadCastMessage()
    count=0;
    public synchronized void FloodMessage(String message) throws IOException
    System.out.print(count);
         for(int i=0;i<count+1;i++)
         try
    {  System.out.print(count);
         output[count].writeObject(message);
         output[count].flush();
         catch(IOException ioException)
    {ioException.printStackTrace();}
         notifyAll();
    public ObjectOutputStream getOutputObject(ObjectOutputStream out,Socket caller,int Ocount)
    try
    { temp = new ObjectOutputStream(caller.getOutputStream());
         AddObjectOutputStream(temp,Ocount);
    ////FloodMessage();
         catch(IOException ioException)
    {ioException.printStackTrace();}
    return temp;     
    public void AddObjectOutputStream(ObjectOutputStream out,int Ocount)
    { ///add new object to array
    count=Ocount;
    output[count]=out;
    System.out.print("\nthe number of output streams : "+count+"\n");
    }

  • Client/server application using sockets

    Hi there,
    I'm trying to create a client/server application using sockets where the client has a GUI of a membership application form for some sort of club. Basically, the user will enter their name, address, membership no. etc in to various Jtext fields and then press a JButton to submit these details to the server. The server will then hopefully just dump these details to a text file.
    Can anyone give me any examples, ideas on how to start, links etc.
    Thanks v. much in anticipation,
    Nick

    Take a browse of the tutorial on sockets: http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html

  • Client & server can use different language when using socket for client/ser

    When building client/server applications using socket , is it that client and server do not need to use both Java as long as they implement the same networking protocol?
    Thanks a lot!

    thank you, DrClap!

  • How to make bank management system using java file system

    Hi, I have some fields
    1.ID
    2. Deposite
    3. Withdraw
    4. Balance
    Now how can i manage this Bank Management System using java file system.
    Thanks in advance.

    Then we're back to (1): Do your own homework. Google has zillions of links on handling files in Java. When you have written some code and have an actual problem, we'll be happy to help you with it.
    (edit) Incidentally, this sounds suspiciously like the sort of problem they set for the certification programs. In which case, don't bother; they're not worth the virtual paper they're printed on.

  • How to design socket client-server app for 2-way communication

    Hi, I am writing a client-server application. I have a single server and many clients. Each client will need the ability to send information to the server at any time. The server will also need the ability to send information to a client at any time. Its this second part that I am not sure how to design. Would I need to create a SocketServer on each client to accept incoming messages, or is there a better way? Thanks

    scranchdaddy wrote:
    Don't my requirements sound a lot like an IM application, where a chat server might need to send a message to a chat client at any time?Not really. If that is what you are designing
    in my opinion one could easily be forgiven for thinking you were deliberately obfuscating your goal...
    How does the server know where the client is? Does it know the IP address of the client?I would imagine the server would contain a directory of IPs? I'm not sure.
    What happens if the client is not running?Then I guess the message would not get delivered.
    What happens if the client is behind a firewall that does not allow incoming connections?How do IM chat clients work? How have people solved this in the past?Typically the server would only care about clients currently connected to the server.
    Maybe you should re-think your design. I don't really have a design, just requirements, that's why I'm writing this post.Your subject says "+How to *design* socket client-server app for 2-way communication+".
    Are you saying you expect someone else to do the design for you?

  • Are there any Client/Server Application (using sockets) design patterns?

    Hi,
    The title of the post nearly says it all. I am searching for different design patterns related with the development of a client/server application. I understand that there must be any different ways on how a client/server application can be developed.
    Regards,
    Sim085
    Disclaimer:
    When I enter in the Socket forum on this site I recieve this message "Thank you for any participation in this forum. Due to a lack of relevant activity, we have decided to archive this forum on June 16, 2006. For future posts on this topic, we suggest you use the Networking forum" and I am not allowed to create a new post! However I can see posts done yesterday! All i did is add the forum in 'my forums'. Does this happen to you people as well?

    Hi Sim085...How are you?
    So look this:
    http://forum.java.sun.com/thread.jspa?threadID=5148926&tstart=75
    I don�t know if is what you want...but I hope in this^^
    Ok man...If you have one example for help you is better.
    [ ]

  • TCP/IP Server Socket using Java Proxy (Sender) ?

    Hi,
    I have requirement to listen certain port for third party POS system using TCP/IP Socket. Since there is no standard SAP TCP/IP Socket Adapter. I am planning to develop using Sender Java Proxy.
    Please advise whether this approach is workable ? or is there any related blog / forum discuss about Socket Server.
    This blog is only for socket client /people/saravanakumar.kuppusamy2/blog/2005/12/15/socket-integration-with-xi
    Thank You and Best Regards
    Fernand

    When you want to have minimal effort, you can create a standalone Java program which listens on a port and transforms the incoming tcp/ip stream to an HTTP message, which you can send to SAP PI.
    With more effort you can create an TCP/IP adapter by your own, according to JCA architecture.
    A sender Java proxy does not have any runnable code itself, so the problem to create a listened is not solved.

  • Client server application using CORBA

    Hi
    I have a basic client server application running using CORBA/idl where the client starts up and the server says hello back to the client. I have figured out the basics but would like some help with these small problems.
    When I start the client, the server says hello. Thats OK. Now I want the client to start a simple java app (called c:\test.java - it works) that I created before. How?
    The next bit is when I close down the app "test" that I start, I want the server to realise that its closing and simply say goodbye on the client. How?
    If anybody can help me, I'd appreciate it.
    Thanks for your time,
    Shaun

    hi,
    to my knowledge, you will have to define a method in idl file and in your client, which server invocates(saying good bye etc) before shutting down..
    ls.

  • Identify the number server calls using java

    how to identify the number server calls that are made for rendering the page, Also have each call transmission data too.using java language.

    What??? What are you talking about? What environment? What server?

  • Authenticate against windows 2000 server securtiy using Java.JNI

    How could you use Java or JNI to read the password and group membeship from the operating system for a given windows 2000 user, from a servlet/class?

    Are you looking to build some sort of single sign-on module? You wouldn't be able to get the password, but you might be able to pass a token indicating the users credentials. You'd have to delve into the MSDN resources to get that.
    Once you figure out how to what you want using COM, you can more easily integrate it into Java using the sourceforge projects Jacob or JAWIN.

  • Client/Server apps using custom objects

    I have wrote an ip transaction server and I am trying to pass objects across to it that don't have to reside on the server. I have created an interface that implements serializable and then the class I am trying to pass implements the interface. I read that as long as the interface is on both the client and the server that the object doesn't need to be using this approach.
    I, however, keep getting a classdefnotfound error for the custom object when I do a readObject().
    Can this really be done?
    Thanks in advance.
    Relevant code snippets:
    interface Workable implements java.io.Serializable
         public abstract int getToWork();
    public class test1 implements Workable
         public int getToWork()
              System.out.println("Test 11 value = ");
              return 1;
    Server code:
    Workable ipdata;
    ipdata = (Workable)in.readObject();//Blows up trying to read object here
    ipdata.getToWork();

    Take a look at the thread on this newsgroup named:
    deserialization loads classes more eagerly than construction?
    That seems similar to your complaint (Java's object serialization not conforming to its own specs about "classes that don't need to be present", in that thread it is a non-serializable member object that blocks things). I get the feeling you hit a bug in Java's serialization mechanism and that it is caused by a faulty heuristic in Java serialization.

  • Restarting System using java

    I am making a software using J F C ,which will be available on cd .I have decided to set the classpath for java in client machine by making a batch file.But i want my program to restart the client machine (that is after taking due permission) automatically.I have heard that could be done using System.loadLibrary and then loading one of win32 dll responsible for doing so?
    Please help!Any code in support are most welcome
    Ashish

    If I understand you right, you want to do this at installation time. Why don't u use a free edition of one of the popular installers (e.g. InstallAnywhere from http://www.zerog.com . It should take care of issues like that.

Maybe you are looking for

  • TNS-12545: Connect failed because target host or object does not exist

    Hi all, I have a bit of a problem, I have gone thru the posts and tried out suggestions but it didn't work. When i type in LSNRCTL> services I get this error: Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC))) TNS-12541: TNS:no listene

  • What exactly is offline website data and what does it mean to clear it?

    What exactly is offline website data and what does it mean to clear it? For what purposes would I clear offline website data?

  • GLOBAL ZONE stuck in shutting_down after applying latest patch cluster

    Hi, after installing the latest patch cluster, my zones on the system are not accessable root@typhoon # zoneadm list -civ ID NAME STATUS PATH BRAND IP 0 global shutting_down / native shared - typhoon-log installed /local/zone/typhoon-log native share

  • 1.4 plugin and auto-download

    OK, the documentation (http://java.sun.com/j2se/1.4/docs/guide/plugin/developer_guide/autodownload.html) says a script is available ( http://java.sun.com/browser/autodownload.js) to force the browser to load the new plugin - problem is that script do

  • Hiding text in Editor

    Hey! I'm trying to create an editor where I'm hiding certain patterns, e.g. I'd like to display the document > VAR > Foo@1000 : ... as > VAR > Foo : ... i.e. hiding the pattern @1000. This might appear multiple times within a line. I've managed to ge