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 7614419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:24:00+00:00 2026-05-31T02:24:00+00:00

I have set up a UDP client/server model that can send string messages to

  • 0

I have set up a UDP client/server model that can send string messages to each other.

I’ve created a custom class LoginRequest which is serialized and sent to the server containing the username and password. When the getters for these variables are called they return null values even though I check the variables before the LoginRequest is sent.

Here is the code for serializing and sending datagram from the client:

private void login(String name, char[] pass) throws SQLException {
    try {
        LoginRequest login = new LoginRequest(name, pass);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(login);
        byte[] buffer= baos.toByteArray();
        oos.close();
        baos.close();
        DatagramPacket packet =
                new DatagramPacket(buffer, buffer.length, InetAddress.getByName(SERVER), 10110);
        DatagramSocket sSocket = new DatagramSocket();
        sSocket.send(packet);
        login.getUsername();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

Here is the code for de-serializing the LoginRequest and reading the username:

private void readMessage() {
    try {
            ByteArrayInputStream bais = new ByteArrayInputStream(cPacket.getData());
            ObjectInputStream ois = new ObjectInputStream(bais);
            Object obj = ois.readObject();
            bais.close();
            ois.close();
            if(obj instanceof LoginRequest) {
                System.out.println("Login request");
                LoginRequest login = (LoginRequest) obj;
                login.getUsername();
            } else {
                System.out.println("Not a login request");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Here is the Code for the LoginRequest:

public class LoginRequest implements Serializable {
/**
 * 
 */
private static final long serialVersionUID = -1379800611469143228L;
private static String username;
private static char[] password;

public LoginRequest(String name, char[] pass) {
    username = name;
    password = pass;
}

public String getUsername() {
    System.out.println("Username: " + username);
    return username;
}

public char[] getPassword() {
    String p = password.toString();
    System.out.println("Password: " + p);
    return password;
}
}

When I attempt to read the username or password after this deserialization, I get a NullPointerException. I will be extremely happy if someone can point me in the right direction.

  • 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-31T02:24:01+00:00Added an answer on May 31, 2026 at 2:24 am

    Drop the static on your attribute usename and password!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Overview: I have set up a server and a client, where both attempt discovery
Typically you have a server and client pair or two peers that connect to
I have a time critical application that needs to send a UDP datagram on
I want to create a server and client that sends and receives UDP packets
I have set up a Django application that uses images. I think I have
I have set of scripts for doing scripted installs. You can use the scripts
I have an application that consists of numerous systems using UDP clients in remote
I have a set of code that, depending on how the program is initiated,
I have two simple Python files: client.py and server.py . The client simply sends
i have rule set up to drop udp/tcp packets with matching strings. however, my

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.