Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6348547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:26:28+00:00 2026-05-24T21:26:28+00:00

I am trying to authenticate user by sending a key and a random number

  • 0

I am trying to authenticate user by sending a key and a random number from the client to the server.

My code is not displaying me the response from the client. I am getting a Null Pointer Exception when I execute my code as below.

import java.io.*;
import java.net.*;
import java.lang.*;

class Client 

{
    public static void main(String args[]) throws IOException
    {

        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("enter the key value");
        int key=Integer.parseInt(br.readLine());
        double random=Math.random()*50;
        System.out.println(random);
        int response=key%((int)random);
        System.out.println(key);
        System.out.println("Authentication begins");
        Socket echoSocket = new Socket("localhost", 2000);
        FileOutputStream fout=null;
        DataOutputStream clientout=null;
        clientout.writeDouble(random);
        clientout.writeInt(key);
        clientout.writeInt(response);    
        fout.flush();
        System.out.println("client is"+response);
        echoSocket.close();

    }
}

import java.io.*;
import java.net.*;
import java.lang.*;

class Server
{
    public static void main(String args[]) throws IOException
    {
        int response2;
        double random2;
        int key2;
        FileInputStream fin=null;
        DataInputStream clientin=null;
        ServerSocket s= new ServerSocket(2000);
        Socket echoSocket=s.accept();
        random2=clientin.readDouble();
        key2=clientin.readInt();
        response2=clientin.readInt();
        response2=key2%((int)random2);
        System.out.println("server is"+response2);
        s.close();
        echoSocket.close();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:26:29+00:00Added an answer on May 24, 2026 at 9:26 pm

    Canned steps for solving most NullPointerExceptions:

    1. Read the stack trace to determine what line of code throws the NPE
    2. Put a breakpoint at that line of code
    3. Using the debugger, when the breakpoint is hit, gigure out what object reference in that line is null
    4. Figure out why that reference is null (this is the only actual hard part so far)
    5. Fix the underlying cause (also potentially difficult)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to authenticate a user by sending a POST request from my
I'm trying to authenticate a user through the RESTful API (not Connect) but I
I'm trying to authenticate to a web server from an android class with the
I'm trying to authenticate a user on my symfony2 server. The authentication works with
I do not know much about encrypting. I am trying to use authenticate user
I'm trying to authenticate againest an ldap server I've created. The user password is
I am trying to authenticate user using LDAP I am using this code: public
I'm trying to authenticate an android client app to my server ruby on rails
I'm getting a Message signature was incorrect exception when trying to authenticate with MyOpenID
I'm trying to authenticate a user against Active Directory using the types in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.