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 12 of 12
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question How to kill TCP connection???

    I have written a server-client program, I can successfully establish TCP connection between serve7r & client using sockets. Now, I have some functionality where server gets a data item from client & does a comparison. I want to break the TCP connection if the 2 data items being compared don't match. M writing in java but I dunno how 2 include tis functionality.

  • #2
    New Coder
    Join Date
    Jan 2011
    Location
    India
    Posts
    31
    Thanks
    0
    Thanked 4 Times in 4 Posts
    You can just use the close methode in the Connection classes.

    For further details see

    http://www.javaworld.com/jw-12-1996/jw-12-sockets.html

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

    Exclamation Client-Server error

    I m having error in my try-catch statements in the client-server program 4 which I had asked the earlier qn.

    The Server:
    import java.io.*;
    import java.net.*;

    class AS
    {
    public static void main(String argv[]) throws Exception
    {
    String clientCar;
    String clientBranch;
    String clientDriver;
    String clientPasswd;

    try {
    ServerSocket socketS = new ServerSocket(9002);
    Socket socket1 = socketS.accept();
    } catch (IOException e) {
    System.err.println("Could not listen on port: ");
    System.exit(1);
    } catch (IOException e) {
    System.err.println("Accept failed.");
    System.exit(1);
    }

    while(true)
    {
    //Socket socket1 = socketS.accept();
    BufferedReader ClientInfo = new BufferedReader(new InputStreamReader(socket1.getInputStream()));
    DataOutputStream ClientOut = new DataOutputStream(socket1.getOutputStream());
    clientCar = ClientInfo.readLine();
    clientBranch = ClientInfo.readLine();
    clientDriver = ClientInfo.readLine();
    clientPasswd = ClientInfo.readLine();
    ClientOut.writeBytes(clientCar);
    ClientOut.writeBytes(clientBranch);
    ClientOut.writeBytes(clientDriver);
    ClientOut.writeBytes(clientPasswd);

    }

    try {
    fin = new FileInputStream(fil);

    // Here BufferedInputStream is added for fast reading.
    buff = new BufferedInputStream(fin);
    dist = new DataInputStream(buff);

    // dist.available() returns 0 if the file does not have more lines.
    while (dist.available() != 0) {

    // this statement reads the line from the file and print it to
    // the console.
    System.out.println(dist.readLine());
    }

    // dispose all the resources after using them.
    fin.close();
    buff.close();
    dist.close();

    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }


    Calendar calendar = Calendar.getInstance();

    java.util.Date now = calendar.getTime();

    java.sql.Timestamp currentTimestamp = new java.sql.Timestamp(now.getTime());
    }
    }

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

    Exclamation Client-Server error part 2

    The Client:

    import java.io.*;
    import java.net.*;
    import java.util.*;

    class Client
    {
    public static void main(String argv[]) throws Exception
    {
    String car;
    String branch;
    String driver;
    String passwd;

    try {
    Socket client1 = new Socket(9002);
    } catch (UnknownHostException e) {
    System.err.println(e);
    System.exit(1);
    } catch (IOException e) {
    System.err.println(e);
    System.exit(1);
    }
    BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
    DataOutputStream ServerOut = new DataOutputStream(client1.getOutputStream());
    BufferedReader ServerInfo = new BufferedReader(new InputStreamReader(vlient1.getInputStream()));
    car = userInput.readLine();
    branch = userInput.readLine();
    driver = userInput.readLine();
    passwd = userInput.readLine();

    Calendar calendar = Calendar.getInstance();
    java.util.Date now = calendar.getTime();
    java.sql.Timestamp currentTimestamp = new java.sql.Timestamp(now.getTime());
    client1.close();

    }
    }

  • #5
    New Coder
    Join Date
    Jan 2011
    Location
    India
    Posts
    31
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Please post the errors which your are getting

  • #6
    New to the CF scene
    Join Date
    Feb 2010
    Location
    3 Locust Street, Suite A Assonet, MA 02702
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use tcpkill command to kill specified in-progress TCP connections. It is useful for libnids-based applications which require a full TCP 3-whs for TCB creation.

    Syntax:-tcpkill -i eth0 { expression }

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

    Question Updated!!!

    Ok I updated my program, corrected the errors etc, now I have to do NTLM authentication & I hve no clue how to go about it. I am trying to implement a Kerberos protocol & I have 2 create challenges also, the prob with Kerberos is that no one offers samples for Kerberos @ the source level bcose its nvr worked form tat level so m clueless how to create challenges & how to implement pure NTLM, anyone with knowledge on such matters pls help. Tks.

  • #8
    New Coder
    Join Date
    Jan 2011
    Location
    India
    Posts
    31
    Thanks
    0
    Thanked 4 Times in 4 Posts
    You can your apache http client libs for ntlm authentication.

    Look at

    http://hc.apache.org/httpcomponents-client-ga/

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

    Internet Explorer Ntlm

    I was looking 4 sample java code on simple NTLM implementation.

  • #10
    New Coder
    Join Date
    Jan 2011
    Location
    India
    Posts
    31
    Thanks
    0
    Thanked 4 Times in 4 Posts

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

    Thumbs up

    Do u noe time-stampping? My time-stampping code doesn work as in Calendar variable isn recognised & my client socket isn recognised. Tis is my curr code.

    Server:

    Code:
     import java.io.*;
    import java.net.*;
    
    class AS2
    {
       public static void main(String argv[]) throws Exception
          {
             String clientCar;
             String clientBranch;
             String clientDriver;
             String clientPasswd;
     
             ServerSocket socketS;
             Socket socket1;
             BufferedReader ClientInfo;
             BufferedInputStream buff;
             DataInputStream dist;
             DataOutputStream ClientOut;
             FileInputStream fin;
             Calendar calendar1;
          
        try { 
               socketS = new ServerSocket(9002);
            } catch (IOException e) {
                System.err.println("Could not listen on port: ");
                System.exit(1);
            }
    
        try {
                socket1 = socketS.accept();
             } catch (IOException e) {
                System.err.println("Accept failed.");
                System.exit(1);
            }
    
             while(true)
             {
                 ClientInfo =
                   new BufferedReader(new InputStreamReader(socket1.getInputStream()));
                ClientOut = new DataOutputStream(socket1.getOutputStream());
                clientCar = ClientInfo.readLine();
                clientBranch = ClientInfo.readLine();
                clientDriver = ClientInfo.readLine();
                clientPasswd = ClientInfo.readLine();
                ClientOut.writeBytes(clientCar);
                ClientOut.writeBytes(clientBranch);
                ClientOut.writeBytes(clientDriver);
                ClientOut.writeBytes(clientPasswd);
             }
    
      try {
              fin = new FileInputStream("CarBranchInfo.txt");
    
             // Here BufferedInputStream is added for fast reading.
             buff = new BufferedInputStream(fin);
             dist = new DataInputStream(buff);
    
             // dist.available() returns 0 if the file does not have more lines.
             while (dist.available() != 0) {
    
             // this statement reads the line from the file and print it to
            // the console.
            System.out.println(dist.readLine());
          }
    
        } catch (FileNotFoundException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
    
          // dispose all the resources after using them.
          fin.close();
          buff.close();
          dist.close();
               
                
               calendar1 = Calendar.getInstance();
    
               java.util.Date now = calendar.getTime();
    
               java.sql.Timestamp currentTimestamp = new java.sql.Timestamp(now.getTime());
          }
    }

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

    Thumbs up Client part

    Code:
     import java.io.*;
    import java.net.*;
    import java.util.*;
    
    class Client
    {
       public static void main(String argv[]) throws Exception
       {
         String car;
         String branch;
         String driver;
         String passwd;
         Socket client1;
         BufferedReader userInput;
         DataOutputStream ServerOut;
         BufferedReader ServerInfo;
         
         try {
               client1 = new Socket(9002);
            } catch (UnknownHostException e) {
                System.err.println(e);
                System.exit(1);
            } catch (IOException e) {
                System.err.println(e);
                System.exit(1);
            }
            
         userInput = new BufferedReader(new InputStreamReader(System.in));
         ServerOut = new DataOutputStream(client1.getOutputStream());
         ServerInfo = new BufferedReader(new InputStreamReader(client1.getInputStream()));
         
         System.out.println("Please provide the car name: ");
         car = userInput.readLine();
         //Scanner car = new Scanner(System.in);
         System.out.println("Please provide the branch name: ");
         branch = userInput.readLine();
         //Scanner branch = new Scanner(System.in);
         System.out.println("Please provide the driver name: ");
         driver = userInput.readLine();
         //Scanner driver = new Scanner(System.in);
         System.out.println("Please provide the password: ");
         passwd = userInput.readLine();
         //Scanner passwd = new Scanner(System.in);
         
         Calendar calendar = Calendar.getInstance();
         java.util.Date now = calendar.getTime();
         java.sql.Timestamp currentTimestamp = new java.sql.Timestamp(now.getTime());
         
         System.out.print(new java.sql.Time(time.getTime())); 
      
         client1.close();
         
        }
    }


  •  

    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
    •