Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: server client upercase

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default server client upercase

    I have to programs: Server and client.
    The client would send a string to server. Server uppercase it and sends it back.
    I know there is a lot of code on the web on doing this. This is a homework so I am trying to learn what I am doing wrong.
    The client has some generated code. Tried to cut out some of it to make it clear.
    Img is of the client.
    EDIT: before my last code change, I was getting connect denied. Now the client freezes.
    EDIT EDIT: Fixed the freeze. Now :Connection timed out: connect
    EDIT EDIT EDIT: Looks like it is getting the Connection, but things are not being done.
     
     
    package server;
    import java.io.*;
    import java.net.*;
    /**
     *
     * @author Hokina
     */
    public class Main {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args)
        {
     
            String InLine; //make string for input
            ServerSocket ser = null;
     
            try {
              ser = new ServerSocket(11234); //consturt the socket for lisining
            }
            catch (IOException e) {
               System.out.println(e);
            }
     
            Socket cli = null;
        try {
               cli = ser.accept(); // Accepts and connects to incoming connections for sending socket
              PrintWriter out = new PrintWriter(cli.getOutputStream(), true); //makes a stream for input
              BufferedReader in = new BufferedReader(new InputStreamReader(cli.getInputStream())); //makes a stream for output
     
     
               // Reads in the line, then outputs the line as upper cased.
               while ((InLine = in.readLine()) !=null)  {
                   out.println(InLine.toUpperCase());
               }
     
            }
        catch (IOException e) {
               System.out.println(e);
            }
            try {
            cli.close();
            ser.close();
            }
            catch (IOException e) {
                System.out.println(e);
            }
        }
     
    }
    }

       private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // Clears text fields
            jTextField1.setText("");
            jTextField2.setText("");
            jTextField3.setText("");
            // TODO add your handling code here:
    }                                        
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            //make vars
            Socket cli = null;
            BufferedReader read = null;
            PrintWriter out = null;
     
        try {
               cli = new Socket(jTextField1.getText() , 11234); // sets up connetion to server.
               out = new PrintWriter(cli.getOutputStream(), true); // sets up stream for output
               read = new BufferedReader(new InputStreamReader(cli.getInputStream()));
        }
        catch (UnknownHostException e) {
            System.out.println("Failed find hostname");
        }
        catch (IOException e) {
            System.out.println("Failed I/O" + e);
            }
                 try {
                    out.write(jTextField3.getText() + '\n'); //send text over connection);
                 }
                 catch (Exception e) {
                     System.out.println("fail" + e);
                 }
                try {
                    jTextField2.setText(read.readLine()); //trys to read in text form server
                    // closes connection
                    cli.close();
                }
                catch (IOException e) {
                    System.out.println("fail" + e);
                }
     
            try {
            out.close();
            read.close();
            cli.close();
            }
            catch (Exception e) {
                System.out.println(e);
            }
        }                                        
     
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            System.exit(0);
        }                                        
    }
    Attached Images Attached Images
    Last edited by Hokorippoi; March 27th, 2011 at 04:43 PM. Reason: update


  2. #2
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: server client upercase

    They look like they are setup o talk to each other. I need to know what the messages are not being passed.

Similar Threads

  1. simple ftp server and ftp client
    By simontkk2005 in forum Java Networking
    Replies: 4
    Last Post: January 26th, 2011, 10:29 AM
  2. client/server socket
    By Java_dude_101 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: January 18th, 2011, 01:16 AM
  3. client server communication
    By Brt93yoda in forum Java Theory & Questions
    Replies: 4
    Last Post: September 2nd, 2010, 04:49 PM
  4. Client/Server
    By Dillz in forum Paid Java Projects
    Replies: 2
    Last Post: June 2nd, 2010, 05:19 AM
  5. [SOLVED] The concept of Server and Client
    By rendy.dev in forum Java Theory & Questions
    Replies: 3
    Last Post: January 18th, 2010, 04:13 AM