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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:17:30+00:00 2026-06-04T16:17:30+00:00

So at this stage I have a server and a client where each of

  • 0

So at this stage I have a server and a client where each of them has both input and output stream.

I am implementing a video streamer using VLC wrapper. Basically, when I choose a video on the client, it sends a string of the object the server should expect to receive next. (videoFile/commentWrite/ratingWrite). It sends all of those three objects on choosing a video so it updates the stream, updates the comment box and the rating box.

The problem now is that when I need to send those headers and receive data I have to use something like:

        replyToServer.writeObject("videoFile");
        replyToServer.writeObject(selectedVideo);       

        //get comments
        listening();

        //get rating
        listening();

So it’s hard coding by knowing in front know many replies your are expecting. Moreover, what if you want to receive something from the server at any point of your work on client, but you cannot use a simple while loop to check on listening() function as it will block all the other functionality.

PS. listener is structured like:

public void listening() throws IOException, ClassNotFoundException {
    String mode = null;
            // blocks the process till gets the output.
        mode =  (String) inputFromServer.readObject();
        System.out.println("Mode Received:" +mode);

    if (mode.equals("videoList")) {
        getListFromSocket();
    } else if [.....]

So… So I understood that it could be done by using threads. I haven’t really done much threads using Java, but is it possible to make some kind of interrupt on (String) inputFromServer.readObject(); or inputFromServer.available() So as soon as it sees that there is something on the stream it jumps to the listening() function?

UPDATE:

by using lxx code I noticed that the null exception I am receiving is due to updating the gui. I have a function updateComments in that listening();. Everything seems to be working fine as I see the comments etc. But still it shows those null exceptions in the console…

    public void updateComments(List<Comment> commentList) {



    commentLabel.setText("<html><div style='width:130px; border: 1px solid black; list-style-type: none; text-align:left;'>");
    if (commentList.size() == 0) {

         commentLabel.setText(commentLabel.getText()+"<font style='font-family: Century Gothic, sans-serif;  font-weight:normal; color:#444;  font-size:9px;'>No comments...</font><br>");

    } else {

    for (Comment tempComment : commentList) {

         commentLabel.setText(commentLabel.getText()+"<div style='margin:3px;'><font style='font-family: Century Gothic, sans-serif;  font-size:9px; color:#333;'>"+tempComment.getUser()+":</font><br>");
         commentLabel.setText(commentLabel.getText()+"<font style='font-family: Century Gothic, sans-serif; font-weight:normal; font-size:8px;'>"+tempComment.getText()+"</font><br>");
         commentLabel.setText(commentLabel.getText()+"<font style='font-family: Century Gothic, sans-serif; font-weight:normal; font-size:7px;'><i>"+tempComment.getDate()+"</i></font></div><hr>");
    }


    }
     commentLabel.setText(commentLabel.getText()+"</div></html>");

}
  • 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-04T16:17:31+00:00Added an answer on June 4, 2026 at 4:17 pm

    Why not put listening(), or a loop which calls listening (your blocking operations) in a Thread:

    new Thread(new Runnable() {
    
        @Override
        public void run() {
            listening();
    
        }
    
    }).start();
    

    This way the blocking operations are in a separate thread and your main code continues executing normally.

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

Sidebar

Related Questions

I have a client-server architecture where the server has its clients do work in
I have a simple server client application. Everything works, but at some stage it
I have this quickBox2d code to add a cricle to the stage: var ball:QuickObject
I haven't yet implemented this, I'm still in the thinking stage, but I have
I have a list of lists that looks like this: x[[state]][[year]] . Each element
I have written a Java server for remote storage (an iSCSI Target). The client
I have a server for a client-server game (ideally the basis for small MMO)
I have a client with a site (built with Kohana framework) which has a
I have a text file, which looks like this: node13 state = free np
I have a JavaScript widget that is hosted on websites. This widget tracks state

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.