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

  • Home
  • SEARCH
  • 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 8316925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:28:05+00:00 2026-06-08T21:28:05+00:00

I need a little help with implementation of reading a data from socket in

  • 0

I need a little help with implementation of reading a data from socket in my application.

I’m working on application which is listening for a data using Socket and parsing received data. The problem is that I need to connect to my device and start the socket so I can receive the data. I was using ServerSocket which is blocking and waiting to stop the other socket, which is sending me the data, and parse the data after that. But I need to be able to read the stream before closing the server’s socket.

So any idea how can I achieve this kind of implementation and which classes I have to use about that?

  • 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-06-08T21:28:08+00:00Added an answer on June 8, 2026 at 9:28 pm

    The following code is what im using to listen broadcast messages from network:

    void startBroadcastListener(final int receivingPort)
    {
        new Thread() 
        {
            public void run() 
            {
                try 
                {
                    int port = receivingPort;
                    dsocket = new DatagramSocket(port);
                    byte[] buffer = new byte[2048];
    
                    DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
                    while (true) 
                    {
                        //System.out.println("Receiving...");
                        dsocket.receive(packet);
                        String msg = new String(buffer, 0, packet.getLength());
                        packet.setLength(buffer.length);
    
    
                        String binaryString = convertHexToBinary(packet.getData()).replaceAll("\\s","");
    
                        //System.out.println(packet.getAddress().getHostName() + ": " + binaryString);
                    }
                }
                catch (Exception e) 
                {
                    e.printStackTrace();
                }
            }
        }.start();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would need little help here. I'm trying to get the git respository from
I need a little help getting a tar file to download from a website.
I need a little help with updating my UI from Runnable/Handler every second. I'm
Need a little help getting the following rule working: RewriteCond %{HTTP_HOST} ^asset.*.domainone\.com [NC,AND] RewriteCond
Need little help to form a properly working regexp (in ruby) to match quoted
Need a little help: I'm using jquery treeview plugin (this one: http://bassistance.de/jquery-plugins/jquery-plugin-treeview/ ). And
Need a little help from you guy's. I am making a check where element
Need a little help with this script. It's working but I'd love a way
I need a little help on this subject. I have a Web application written
I need little help for url rewriting in wordpress. basically what i need: mydomain.com/mysomewordpresspost

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.