Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs down Failed Client-Server Communication

    I hve written a server program & a client program. The server is supposed to echo watever is typed in the client. I hve to get 16 values to be echoed. I hve created a string and all the values are added to this string. When I pass the string to the server, it doesn get echoed by the server. In fact server hangs @ tat part after establishing connection with the client. I am at my wits end!Can someone run the code for me & explain why it hangs when its supposed to echo the value in server? I hve changed my code 7 times already still I can't understand why it hangs, tis is really a desperate call, stuck with tis 4 4 days alreay.

    SERVER PROGRAM:
    Code:
     import java.io.*;
    import java.net.*;
    import java.util.*;
    
    public class AS3{
        public static void main(String[] args ){
            int i = 1;
            try{
                 ServerSocket s = new ServerSocket(9001);
    
                 for (;;){
                     Socket incoming = s.accept( );
                     System.out.println("Spawning " + i);
                     new RealEchoHandler(incoming, i).start();
                     i++;
                 }
            } catch (Exception e){ System.out.println(e); }
        }
    }
    
    class RealEchoHandler extends Thread{
    	DataInputStream in;
    	DataOutputStream out;
    	private Socket incoming;
        private int counter;
    
        public RealEchoHandler(Socket i, int c){
            incoming = i;
            counter = c;
        }
    
        public void run(){
            try {
    
                in = new DataInputStream(incoming.getInputStream());
    			out = new DataOutputStream(incoming.getOutputStream());
    
                boolean done = false;
                String str="";
                out.writeUTF("Connected!\n");
                out.flush();
                while (!done){
    				out.writeUTF(">");
    				out.flush();
                    str = in.readUTF();
                    System.out.println(in+":"+str);
                    if (str == null)
                        done = true;
                    else{
                        out.writeUTF("Echo (" + counter + "): " + str+"\n");
                        out.flush();
                    }
                }
    
                incoming.close();
             } catch (Exception e){
                 System.out.println(e);
             }
        }
    
    
    }
    CLIENT:

    Code:
     import java.io.*;
    import java.net.*;
    import java.util.*;
    class Client3{
    	public static void main(String[] args) {
    		String store="";
    		String clientCar="";
    		String clientBranch="";
    		String clientDriver="";
    		String clientPasswd="";
    
    		DataOutputStream out;
    		DataInputStream in;
    		try {
    		    Socket t = new Socket("127.0.0.1", 9001);
    
                in = new DataInputStream(t.getInputStream());
                out = new DataOutputStream(t.getOutputStream());
                BufferedReader br = new BufferedReader
                         (new InputStreamReader(System.in));
                boolean more = true;
    			System.out.println(in.readUTF());
                while (more) {
    				clientCar = in.readUTF();
                    clientBranch = in.readUTF();
    				clientDriver = in.readUTF();
    				clientPasswd = in.readUTF();
                    store = store + clientCar+clientBranch+clientDriver+clientPasswd;
    			    
                    out.flush();
    				store = in.readUTF();
                    if (store == null)
                        more = false;
                    else
                        out.writeUTF(store + "\n");
                }
    
             } catch(IOException e){
    			    System.out.println("Error" + e);
    	     }
    	     System.out.println(str);
         }
    }

  • #2
    New Coder
    Join Date
    Jan 2011
    Location
    India
    Posts
    31
    Thanks
    0
    Thanked 4 Times in 4 Posts
    find the below code. Its working... But I am not sure whether it is working the way you intended.

    The problem with your code is. The both your server and client was on read mode. But no one was sending the data. I manipulated your code to make one guy to write and other guy to read. So the bottom line is, while one program is reading other should be writing and vice versa. Now you would be able to manipulate the code for your need.

    Cheers...
    PHP Code:
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.net.ServerSocket;
    import java.net.Socket;


    public class 
    AS3{
        public static 
    void main(String[] args ){
            
    int i 1;
            try{
                 
    ServerSocket s = new ServerSocket(9001);

                 for (;;){
                     
    Socket incoming s.accept( );
                     
    System.out.println("Spawning " i);
                     new 
    RealEchoHandler(incomingi).start();
                     
    i++;
                 }
            } catch (
    Exception e){ System.out.println(e); }
        }
    }

    class 
    RealEchoHandler extends Thread{
        
    DataInputStream in;
        
    DataOutputStream out;
        private 
    Socket incoming;
        private 
    int counter;

        public 
    RealEchoHandler(Socket iint c){
            
    incoming i;
            
    counter c;
        }

        public 
    void run(){
            try {

                
    in = new DataInputStream(incoming.getInputStream());
                
    out = new DataOutputStream(incoming.getOutputStream());

                
    boolean done false;
                
    String str="";
                
    out.writeUTF("Connected!\n");
                
    out.flush();
                while (!
    done){
                    
    out.writeUTF(">");
                    
    out.flush();
                    
    str in.readUTF();
                    
    System.out.println(in+":"+str);
                    if (
    str == null)
                        
    done true;
                    else{
                        
    out.writeUTF("Echo (" counter "): " str+"\n");
                        
    out.flush();
                    }
                }

                
    incoming.close();
             } catch (
    Exception e){
                 
    System.out.println(e);
             }
        }



    PHP Code:
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.Socket;
    class 
    Client3{
        public static 
    void main(String[] args) {
            
    String store="";
            
    String clientCar="";
            
    String clientBranch="";
            
    String clientDriver="";
            
    String clientPasswd="";

            
    DataOutputStream out;
            
    DataInputStream in;
            try {
                
    Socket t = new Socket("127.0.0.1"9001);

                
    in = new DataInputStream(t.getInputStream());
                
    out = new DataOutputStream(t.getOutputStream());
                
    BufferedReader br = new BufferedReader
                         
    (new InputStreamReader(System.in));
                
    boolean more true;
                
    System.out.println(in.readUTF());
                while (
    more) {
                    
    System.out.println(in.readUTF());
                    
    clientCar br.readLine();
                    
    clientBranch br.readLine();
                    
    clientDriver br.readLine();
                    
    clientPasswd br.readLine();
                    
    store store clientCar+clientBranch+clientDriver+clientPasswd;
                    
    out.writeUTF(store);
                    
    out.flush();
                    
    store in.readUTF();
                    if (
    store == null)
                        
    more false;
                    else
                        
    out.writeUTF(store "\n");
                }

             } catch(
    IOException e){
                    
    System.out.println("Error" e);
             }
    //         System.out.println(str);
         
    }


  • Users who have thanked sandeep.e for this post:

    susanmg (02-07-2011)

  • #3
    New Coder
    Join Date
    Jan 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Timestampping

    Tks a lot for ur help Sandeep I actually jus fixed the issue when I saw the code but I will definitely run ur code bcose my server side echo looks messy. Do u by any chance noe timestampping? I am able to find timestamp for curr time but I wanted timestampping where the timestamp differs from system time by 1 min.I think I can settle tat bcose my curr timrestamp is working but I dunno about how to set up Challenges for Kerberos, m required to encrypt a messsage, I hve a workign encryption code but I dunno how to adapt it for Kerberos. Do u hve any background in Kerberos? Any knowledge would be gr8ly appreciated. Thanks once again.

  • #4
    New Coder
    Join Date
    Jan 2011
    Location
    India
    Posts
    31
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Good Resource for kerberos

    http://web.mit.edu/Kerberos/

  • #5
    New Coder
    Join Date
    Jan 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up Kerberos

    Hmm, I have seen this before, mebbe I will read on it more. I actually meant sample java code 4 Kerberos, anything which would describe how Kerberos challenges were created, tks anyway.

  • #6
    New Coder
    Join Date
    Jan 2011
    Location
    India
    Posts
    31
    Thanks
    0
    Thanked 4 Times in 4 Posts
    The following link clearly explains how to do a kerberos login.

    http://download.oracle.com/javase/1....le-signon.html

    Can you tell me what exactly you are trying to do.

    I have worked on kerberos 2 years back, but on C and Solaris platform.

  • #7
    New Coder
    Join Date
    Jan 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Lightbulb

    I am supposed to do a simplified version of the Kerberos authentication, I shud create 4 programs- Server, Client, Domain Controller and V stands for one more file I forgot the name. The server shud echo watever is typed by the user in the client after establishing connection. Then it shud read from file & do a comparison. Comparision is ok, I can do tat-its basic Java. Now both, client & server shud hve timestamps. I hve written code for a basic timestamp which finds current date & system time. M trying to figure out how the captured timestamp shud differ by system time by 1 min. Then in V I need to put the encryption code, for that I found an AES code sample. Problem is within the AES code, how do I establish session key & create challenge. For session key, I think I can jus write a function to generate a random number. But creating challenge, I have to see. Furthermore under V, I have to use NTLM authentication which I hve found an example but its too long will see how to change it. Domain Controller contains nothing except the md5 hash algorithm. I hven tested the V and DC files yet, I think will try to settle watever I noe then check. This basically covers wat all implementation is required of Kerberos.


  •  

    Tags for this Thread

    Posting Permissions

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