Results 1 to 2 of 2

Thread: Multple Clients

  1. #1
    samson is offline Member
    Join Date
    Mar 2007
    Posts
    16
    Rep Power
    0

    Default Multple Clients

    How can we implement multiple clients in a client server application

  2. #2
    ferosh is offline Member
    Join Date
    Mar 2007
    Posts
    11
    Rep Power
    0

    Default

    Java Code:
    import java.net.*;
    import java.io.*;
    
    public class MultiServerThread extends Thread {
        private Socket socket = null;
    
        public MultiServerThread(Socket socket) {
    	super("MultiServerThread");
    	this.socket = socket;
        }
    
        public void run() {
    
    	try {
    	    PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
    	    BufferedReader in = new BufferedReader(
    				    new InputStreamReader(
    				    socket.getInputStream()));
    
    	    String inputLine, outputLine;
    //Some protocol to process the input
    	    KnockKnockProtocol kkp = new KnockKnockProtocol();
    	    outputLine = kkp.processInput(null);
    	    out.println(outputLine);
    
    	    while ((inputLine = in.readLine()) != null) {
    		outputLine = kkp.processInput(inputLine);
    		out.println(outputLine);
    		if (outputLine.equals("Bye"))
    		    break;
    	    }
    	    out.close();
    	    in.close();
    	    socket.close();
    
    	} catch (IOException e) {
    	    e.printStackTrace();
    	}
        }
    }

Posting Permissions

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