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: TCP Problem

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default TCP Problem

    Client:
    public static void updateTest(){
    		try{
    			Socket clientUpdate = new Socket(host, 1026);
    			BufferedReader in = new BufferedReader(new InputStreamReader(clientUpdate.getInputStream()));
    			DataOutputStream out = new DataOutputStream(clientUpdate.getOutputStream());
     
    			out.writeBytes(Version);
    			//Client those not write out Version to server when I add this
    			//System.out.println(in.readLine());
     
    			clientUpdate.close();
    		}catch(Exception e){
    			System.out.println(e);
    			System.out.println("Error: Test.updateTest()");
    		}
    	}
    Server:
    public static void update(){
    		try{
    			Socket connectUpdate = updateSocket.accept();
    			BufferedReader in = new BufferedReader(new InputStreamReader(connectUpdate.getInputStream()));
    			DataOutputStream out = new DataOutputStream(connectUpdate.getOutputStream());
     
    			String Data = in.readLine();
    			System.out.println(Data);
    			/*
    			 * When I add this to the code, the server doesnt even receive the string Data from the client
    			if(Data.equals("1.0.0.0")){
    				out.writeBytes("up to date");
    			}else{
    				out.writeBytes("Updating");
    			}
    			*/
     
    			connectUpdate.close();
    		}catch(Exception e){
    			System.out.println(e);
    			System.out.println("Error: update()");
    		}
    	}

    I have tried so many ways to fix this, like closing the in and outs at different times. I even tried using PrintWriter. I hav no clue why the server wont write back to the client.

    --- Update ---

    Please dont laugh at me, I fixed it, the shame.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: TCP Problem

    Having problems is nothing more than a sign of attempt.
    Fixing them is a sign of achievement.
    I see no shame

Similar Threads

  1. Sockets and TCP packets
    By Raadush in forum Java Networking
    Replies: 1
    Last Post: May 14th, 2012, 05:58 PM
  2. Need TCP help
    By Blackbird in forum Java Networking
    Replies: 2
    Last Post: July 2nd, 2011, 06:18 PM
  3. Replies: 0
    Last Post: February 24th, 2011, 06:31 AM
  4. TCP Over UDP
    By azarakhsh in forum Java Networking
    Replies: 3
    Last Post: July 15th, 2009, 07:21 AM
  5. Replies: 0
    Last Post: May 3rd, 2009, 10:55 AM