Results 1 to 4 of 4
  1. #1
    melbon is offline Member
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    Default ClientHandler & Server

    I want to ask how I must edit my code instead Server send me Date and Time to send my SUM of two numbers?

    This is My ClientHandler
    Java Code:
    import java.net.*;
    import java.io.*;
    import java.text.*;
    import java.util.*;
    
    public class ClientH extends Thread  {
    	protected SimpleDateFormat sdf; 
    	protected Socket socket;
    	protected Vector threadPull;
    	
    	public ClientH(Socket incoming, Vector threadPull) {
    		socket = incoming;
    		this.threadPull = threadPull;
    		sdf = new SimpleDateFormat("dd/MM/yyyy  hh:mm:ss");
    		System.out.println ("New thread");
    		threadPull.add(this);		
    	}
    	
    	public void run() {
    		String outStr;
    		System.out.println("Starting thread!");
    		
    		try {
    			BufferedReader in
    				= new BufferedReader(
    					new InputStreamReader(
    						socket.getInputStream()));
    			PrintWriter out
    				= new PrintWriter(
    					new OutputStreamWriter(
    						socket.getOutputStream()));
    						
    			out.println("Hello! ...");
    			out.println("Enter BYE to exit.");
    			out.flush();
    			
    			while (true) {
    				String str = in.readLine();
    				System.out.println("From client:" + str);
    				if (str == null) {
    					break;
    				} else {
    
    					outStr = "Now is " + sdf.format(new Date());
    					out.println("Echo: " + outStr);
    					out.flush();
    					if (str.trim().equals("BYE"))
    						break;
    					}
    			}
    			socket.close();
    		} catch (IOException e) { e.printStackTrace();}
    		finally {
    			threadPull.remove(this);
    		}
    	}
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Are you trying to change someone's code to suit your assignment's requirements so that you can hand in the code as yours?

  3. #3
    melbon is offline Member
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    Default

    хаха No, of course. This code was for my homework but tomorrow I will have a classwork and my teacher says me: Please think how you can sum two numbers. I have server and client and clienthandler for my homework but I can't guess how do it ...

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Well the client sends two integers, you retrive them on the server and add them together using the plus operator (+). You then send back the result (the sum) as the response from the server.

Similar Threads

  1. Ping a server when server is not in the localhost..
    By kshitiz in forum New To Java
    Replies: 1
    Last Post: 03-19-2009, 09:17 PM
  2. smtp server configuration with jboss server
    By vilas_patil in forum Java Servlet
    Replies: 0
    Last Post: 01-05-2009, 01:18 PM
  3. Replies: 0
    Last Post: 09-18-2008, 05:07 PM
  4. Does any file in an FTP server ends up in an HTTP server?
    By islamfunny in forum CLDC and MIDP
    Replies: 4
    Last Post: 08-15-2008, 04:30 PM
  5. Replies: 2
    Last Post: 07-15-2008, 06:11 PM

Posting Permissions

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