Blocking io server: looping in.read()

Hello,
i need some advice on my blocking io server,
the thing is every registered client has a thread which handles the reading
i have some kind of protocol implementation but my question is, would i rather use something like this:
@Override
public void run()
if(id == -1)
if (in.available() > 1)
id = in.read()
if(id != -1)
if (in.avaiable() > 1)
size = in.read();
if(size != -1)
if(in.avaiable() > size)
in.read(...)
SLEEP(60);
}or would i do
Hello,
i need some advice on my blocking io server,
the thing is every registered client has a thread which handles the reading
i have some kind of protocol implementation but my question is, would i rather use something like this:
@Override
public void run()
if (id == -1)
id = in.read()
if(id != -1)
size = in.read();
if(size != -1)
in.read(...)
SLEEP(60);
}but the last one doesnt seem efficient, because we are not sure how long it would block, an solution to the last one would be to set the socket timout to 60
but i'm not sure if this would be alright or if the first one would be the best no matter what
Thanks in advance

796870 wrote:
so i should just invoke in.read() and not availability check,Yes.
but that makes think like i need some sort of check
to see if it doesn't block for longer then a defined time out..Why? Has this thread got anything better to do than to block on read()?
And if you use socket.setSoTimeout() what are you going to do when it happens?
try {
   int nextbyte = in.read();
   if (nextbyte<0) throw new java.io.EOFException();
   // handle nextbyte
} catch (SocketTimeoutException ste) {
   // what are you going to do here?
}Edited by: tschodt on Sep 30, 2010 10:06 PM

Similar Messages

  • Exiting a server loop

    hi guys,
    does anyone know the correct way to exit a server loop, at the moment i have ....
    while(!SrvInput.getEndProgStatus()){          
    sk = skt.accept();
    System.out.println("Accepting new client connection");
    serverThread st = new serverThread(sk, conn);
    st.start();
    this just loops around creating a new thread for every client that connects, i have a class SrvInput which reads input from the console so if the user types "quit" the end prog status flag is set to true and the server exits.
    the problem is that for it to exit i need one more person to connect since it blocks on the accept call.
    Does anyone know how i can sort this out
    thanks for any help

    Hi.
    I'm trying to solve the same problem. I solve it, sending myself a Socket conection and then existing the while code like this:
        public void run()
            while (!isFinish())
                try
                    System.out.println("Waiting for connections.");
                    Socket client = serverSocket.accept();
                    if (!isFinish())
                        System.out.println("Accepted a connection from: "+client.getInetAddress());
                        LocationThread connect = new LocationThread(client);
                }catch(Exception e)
                    System.out.println(e.getMessage());
                    e.printStackTrace();
            try
                System.out.println("Server exiting");
                join(); // remove  join(), this a test.....
                serverSocket.close();
                System.out.println("Server has exit");
            }catch(Exception e)
                System.out.println("Error al cerrar el Socket");
        }This code belongs to the server side.
    I do this, in a Button in a GUI interface.
            try{
                location.setFinish(true);
                Socket s = new Socket(InetAddress.getLocalHost(),Integer.parseInt(result));
            }catch(Exception e)
                System.out.println("Error al tratar de terminar el servidor");
            }But I have a problem, I want my server to wait for their childs to finish, How can I do it?.
    a Join() , do the server to hang.
    Any suggestion ?.

  • Curve 9360 "contenct blocked or server unresponsive"

    Hi Guys, I'm new here and I put this topic initially in the wrong forum (Tour). Anyway I'm trying to resolve a problem with my 9360 youtube videos. Everytime I wan to watch anything on youtube I got the same result :contenct blocked or server unresponsive. I rebooted phone few times, cleared cache and also have done all 3 steps withs succesfully receiving messages etc (sending new service books) as I have found this info on Tour forum.  If it is connected via wifi it works without any problems. I am on the contract with unlimited data plan and generally internet works well. Surprisingly I can watch all the videos from the naughty sites but not youtube :-) Staff at the shop is totally no use, helpline of the provider after "investigating the problem" told me that it will be a problem withe device. No surprise as they know that this phone is just over a year old by few weeks. Any suggestions how to fix this problem will be very appreciated...

    Hi garrison
    Please Check this Knowledge Base :
    KB19091 : Error "Content not available. Server is blocked or unresponsive" occurs when attempting to access videos on m.youtube.com from the BlackBerry smartphone
    Click " Like " if you want to Thank someone.
    If Problem Resolves mark the post(s) as " Solution ", so that other can make use of it.

  • Writing Java Non-Blocking Socket Server for  Winsock Client

    Hi.
    Im a newbie to Sockets. I need to write a Non-Blocking Socket server (using java.nio) that accepts connection and reads the data sent by WinSock clients, and write them to another winsock client. Its quite intriguing. How do I do that? Is it possible?
    Thanks in advance
    Arun

    Well, in traditional 4.2 BSD sockets, you'd fill up a set of filedescriptors of connections (an array of bits usually), and push that in the read parameter of a call to 'select'. Select then blocks until at least one of the file descriptors become available for reading, or writing if you also made an fd_set full of file descriptors (but you can usually write freely to a socket, so there is not much use for that). Then you start finding out which of these file descriptors have actually become available for reading, and you pass those to a bunch of worker-threads. The advantage is that your set of worker-threads can be quite small, while your number of connections can still be quite large (unless, of course, everyone of your clients start talking all at once, but that is no different from the one-socket-one-thread-model that java.net.* forces upon you).
    In java, the 'select' call is replaced by a call to java.nio.channels.Selector.select(); and then the fishing out of the selected stuff comes from java.nio.channels.Selector.selectedKeys().
    To add a thingy to a selector, use (for example) java.nio.channel.ServerSocketChannel.register(Selector, ops, att);
    whereby the ops parameter is the kind of action you'd like to select this channel for; SelectionKey.OP_READ etc..
    The workerthread bit is also easy to write, but I leave that to you as an exercise.

  • HT2443 loops are in the browser when you the loop message reads this file type is not supported

    loops are in the browser when you the loop message reads this file type is not supported

    gloucester
    In case you did not find it, the following is a copy/paste of the Announcement on Premiere Elements 19/NVIDIA GeForce
    that appears at the top of this forum.
    Premiere Elements 10 NVIDIA Video Card Driver Roll Back
    If you are a Premiere Elements 10 user whose Windows computer uses a NVIDIA GeForce video card and you are experiencing
    Premiere Elements 10 display and/or unexplained program behavior, then your first line of troubleshooting needs to be rolling
    back the video card driver version instead of assuring that it is up to date.
    Since October 2013 to the present, there have been a growing number of reports about display and unexplained workflow
    glitches specific to the Premiere Elements 10 user whose Windows computer has a NVIDIA GeForce video card. If this applies
    to you, then the “user to user” remedy is to roll back the NVIDIA GeForce video card driver as far as is necessary to get rid of
    the problems. The typical driver roll back has gone back as far as March – July 2013 in order to get a working Premiere
    Elements 10. Neither NVIDIA nor Adobe has taken any corrective action in this regard to date, and none is expected moving forward.
    Since October 2013, the following thread has tried to keep up with the Premiere Elements 10 NVIDIA reports
    http://forums.adobe.com/thread/1317675
    Older NVIDIA GeForce drivers can be found
    http://www.nvidia.com/Download/Find.aspx?lang=en-us
    A February 2014 overview of the situation as well as how to use the older NVIDIA GeForce drivers for the driver roll back can be found
    http://atr935.blogspot.com/2014/02/pe10-nvidia-video-card-roll-back.html
    ATR

  • The project cannot be checked out because the server is in read-only mode.

    Receiving the message "The project cannot be checked out because the server is in read-only mode." when a project manager is trying to access a project. He is a backup PM, and I'm wondering if that's why he is getting the message (since he is
    not the Owner or Status Manager of the project he is trying to access). We are using SharePoint permissions in Project Server 2013.

    Hi,
    I have a solution that might work for you, please follow steps below:
    1) Go to your project schedule, make a small modification to any task on schedule and 'Publish' the project.
    2) While your project is being published and saved, open another window 
    Server Settings -> Manage Queue Jobs
    3) Here you can view the progress of your current Project Publishing update, check if all goes smooth and your project is published successfully without indicating any errors :
     ( to view any error look at the last column of
    table on Manage Queue Job page)
    4) Also in your Project window see if the project is published and not saved as Draft.
    Basically this will give you a fair idea of your project being published or not.
    Regards

  • The Index Server is in Read Only Mode

    Hi,
    In our test environment ALL of our jobs are failing. The message in every failed Job Log is:
    11/18/05 10:25:15- Starting to run operations (1 total) for job 'Search Update 2 - Run Once'. Will stop on errors. (PID=14064)11/18/05 10:25:16- *** Job Operation #1 of 1: System Agent 'Search Update Agent' [Run as owner 'Administrator']11/18/05 10:25:16- The index server is in read-only mode.11/18/05 10:25:16- The index Server is inaccessible. Search Update cannot continue and will terminate.11/18/05 10:25:16- *** Job Operation #1 failed: Call to perform operation #1 failed with error (0x80044301): (null) (0x4)11/18/05 10:25:16- Call to perform operation #1 failed with error (0x80044301): (null)
    has anybody seen this before, and how can I correct it?
    Thanks,Shawn

    The search server goes into read only mode in response to certain error conditions.  Simply restart the service to put the search server back into R/W mode.  The server will attempt to self repair on startup.  You should review your recent search server logs to see if there are errors that may have caused the transition to read only mode.  If problems persist, contact tech support for further assistance in troubleshooting.

  • Com.evermind.server.http.HttpIOException: Read timed out

    Hello,
    I am using embded oracle oc4j server and getting following exception, and I cant fine httpd.conf file to increase KeepTimeout
    ERROR : HttpRequestHandler-1229 com.tcs.sgv.common.exception.BaseException - The stack trace is:
    com.evermind.server.http.HttpIOException: Read timed out
         at com.evermind.server.http.EvermindServletInputStream.read(EvermindServletInputStream.java:92)
         at javax.servlet.ServletInputStream.readLine(ServletInputStream.java:138)
         at com.hhc.MultipartInputStreamHandler.readLine(MultipartRequest.java:831)
         at com.hhc.MultipartInputStreamHandler.readLine(MultipartRequest.java:808)
         at com.hhc.MultipartRequest.readRequest(MultipartRequest.java:394)
         at com.hhc.MultipartRequest.<init>(MultipartRequest.java:222)
         at com.tcs.sgv.fms.requesthandler.NotingRequestHandler.getNotings(NotingRequestHandler.java:1250)
         at com.tcs.sgv.fms.requesthandler.NotingRequestHandler.processRequest(NotingRequestHandler.java:304)
         at com.tcs.sgv.common.servlet.FrontServlet.processRequest(FrontServlet.java:171)
         at com.tcs.sgv.common.servlet.FrontServlet.doPost(FrontServlet.java:112)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:778)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
         at java.lang.Thread.run(Thread.java:534)
    - 10 Jul 2009 05:10:24,782 - 703516 milliseconds
    Please help me regarding this problem

    Oracle have their own support forums at http://otn.oracle.com
    You may also want to search MetaLink.

  • Diagnostic-code: smtp;550 message was blocked by server (GWAVA blocked

    I am having problems sending emails
    diagnostic-code: smtp;550 Message was blocked by server (GWAVA blocked: ipreputation, reference ID: ,
    The message is as follows:
    Reporting-MTA: dns;BLU004-OMC4S31.hotmail.com
    Received-From-MTA: dns;BLU436-SMTP7
    Arrival-Date: Fri, 6 Jun 2014 09:57:27 -0700
    Final-Recipient: rfc822;xxxxxx@xxxxxxx
    Action: failed
    Status: 5.5.0
    Diagnostic-Code: smtp;550 Message was blocked by server (GWAVA blocked: ipreputation, reference ID: str=0001.0A0B0201.5391F2F9.0044,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1, fgs=0)
    Any help would be great its been happening for a few days

    Have you setup a Accepted Domain for your SMTP domain on the Exch server?
    http://technet.microsoft.com/en-us/library/bb124423(v=exchg.141).aspx &
    http://technet.microsoft.com/en-us/library/bb124911(v=exchg.141).aspx#EMC
    And you may want to setup an EAP -
    http://technet.microsoft.com/en-gb/library/bb125137(v=exchg.141).aspx
    Sukh

  • Help with a loop to read every 10th word

    i have this loop which reads in every 10th word starting from position 1, from the vector but now i want to be able to loop though it again and get every 10th word starting from pstion2 so when i first print it out it prints out words 1, 11, 21, 31 and so on and then i loop though it again to print out words 2, 22, 32, 42 and so on and then 3, 13, 13, and so on could anyone give me any solutions please
    thanks jason
    Enumeration e = v.elements();
    Object o;
    for(int i = 0;e.hasMoreElements();i++) {
    o = e.nextElement();
    if (i%10 == 0){ System.out.println(o.toString()); }

    Use code tags when posting code.
    It's interesting that some other guy asked about a for loop like that a week ago. (http://forum.java.sun.com/thread.jsp?forum=31&thread=323439) Are you the same person with a different name? Or are you taking the same course?
    As I said when I answered that question, and as should be pretty selfevident if you actually understand what the for loop you have is doing, you can select which word you print out by changing the initial value of 'i' in your loop. To print word number 2,12 etc you set 'i' to
    9 at the start.

  • Prevent file deletion on server but allow read/write permissions

    So, I have several iMacs that are basically public computers.  They will all access a shared server.  The machines need to possess all of the user permissions of a "read/write" user with the EXCEPTION of being allowed to delete.  As it is now, a random user could delete our entire server in two clicks.  So, I need to somehow secure our data while still allowing the "reading" and "editing" of files.
    Here's what I need to do:
    •  Somehow disable the delete file function altogether (while still maintaining read/edit permissions) or
    •  Find some 3rd party app or workaround that prompts the user with a password dialogue box in order to execute the "delete" function or
    •  Somehow apply permissions to a specific folder on the server that enables read/edit, but disables file deleting by users
    I set the permissions of my trash folder to "read only" however, this only prevents deleting local files and doesn't prohibit deleting files from the shared drive.
    Thoughts?

    I'd rethink the requirements.
    The literal answer is that yes, you can mark the files as being undeletable.
    The access control list setting via the command line chmod command is something akin to the following:
    chmod +a "groupname deny delete"
    In practice, these same requirements do allow the shared files to be effectively deleted; via overwrite.  (This is why the Unix-layer file protections don't bother to differentiate write from delete access.)  These requirements also allow partial file corruptions, a situation which tends to be far more pernicious.

  • Je ne peux pas me servir d'adobe reader, il me demande un # de série et j'en ai pas

    je ne peux pas me servir d'adobe reader, il me demande un # de série et j'en ai pas

    Adobe Reader does not require a serial number. Could it be that your problem relates with Digital Editions?

  • After ios 8.02 update iCloud Drive is stuck in a loop that reads "upgrading" with a spinning wheel spokes for the last 48 hours.

    After ios 8.02 update iCloud Drive is stuck in a loop that reads "upgrading" with a spinning wheel spokes for the last 48 hours.

    There's a solution posted here that may work for you: iCloud Drive won't stop upgrading.

  • How to get server data without reading from the socket stream?

    My socket client checks for server messages through
                while (isRunning) { //listen for server events
                    try {
                            Object o = readObject(socket); //wait for server message
                                tellListeners(socket, o);
                    } catch (Exception e) {
                        System.err.println("ERROR SocketClient: "+e);
                        e.printStackTrace();
                    try { sleep(1000); } catch (InterruptedException ie) { /* ignore */ }
                }//next client connectionwith readObject() being
        public Object readObject(Socket socket) throws ClassNotFoundException, IOException {
            Object result = null;
    System.out.println("readObject("+socket+") ...");
            if (socket != null && socket.isConnected()) {
    //            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                ObjectInputStream ois = new ObjectInputStream(new DataInputStream(socket.getInputStream()));
                try {
                    result = ois.readObject();
                } finally {
    //                socket.shutdownInput(); //closing of ois also closes socket!
        //            try { ois.close(); } catch (IOException ioe) { /* ignore */ }
            return result;
        }//readObject()Why does ois.readObject() block? I get problems with this as the main while loop (above) calls readObject() as it's the only way to get server messages. But if i want to implement a synchronous call in adition to this asynchronous architecture (call listeners), the readObject() call of the synchronous method comes to late as readObject() call of the main loop got called before and therefore also gets the result of the (later) synchronous call.
    I tried fideling around with some state variables, but that's ugly and probably not thread safe. I'm looking for another solution to check messages from the server without reading data from the stream. is this possible?

    A quick fix:
    - Add a response code at the beginning of each message returned from the server indicating if the message is a synchronous response or a callback (asynch);
    - Read all messages returned from the server in one thread and copy callback messages in a calback message queue and the synch responses in an synch responses queue;
    - Modify your synchronous invocation to retrieve the response from the responses queue instead from the socket. Read the callback messages from the corresponding queue instead from the socket.
    Also take a look at my website. I'm implementing an upgraded version of this idea.
    Catalin Merfu
    High Performance Java Networking
    http://www.accendia.com

  • How to reproduce Building Blocks Synth apple loop

    hi, a very specific question that you cant answer unless you listen to sample in question -  a sample in LPX apple loops called Building Blocks Synth. There is a bass line and a recurring synth chord which closes out every time it appears I  think with some kind of filter effect - a bit like a closing hi hat on a plucky synth - a sound I  just think is fantastic, but for the life of me cannot work out how it is done. If you get a chance can you cast your expert ear and for those experts , let me know how you think you get the synth sound and  effect. You can hear it better if you copy into a track and boost the high end and low end  EQ .
    I would not normally ask such a question on here but it is bugging me and I could spend my life looking at tutorials to try and work out what it is but not get there.
    Many thanks in advance for anybody who takes the time to listen to it.
    A related question if anyone happens to know: if I include the loop in a song and successfully commercialise it, is it royalty fee?

    I have a a problem a bit like the one described previously.
    In Set. 2007 I bought my first mac...an iMac 24".
    3-4 months later I had trouble with my HD. The tech support told me that my HD was damaged and could not be fixed. They couldn`t explain why, but they changed my old HD with a new one and problem solved.
    Last month as I was installing the snow leopard operating sistem my iMac froze in the midle of the instalation procedure. I turned it off holding down the power button, and when I turned the power back on I got that flashing folder with a question mark in the middle. In short...after trying everything (formating, partitioning etc) I took it to the shop to hava a look.
    The tech guy just got off the phone with me saying that my HD was damaged and could not be repaired. The only solution is to replace it with a new one.
    In 2 years I had to change 2 HD`s!!!!
    My only guess is that bootcamp might have something to do with it cause it frooze the computer lots of times requiring me to turn it off by pressing and holding down the power button one to many times.
    Does anybody know any other reason for this to have happended?
    Could the installation of snow leopard have had anything to do with this?

Maybe you are looking for

  • Error message when updating 30GB ipod

    I keep getting this error message telling me my ipod was unable to update, whenever I attempt to update my ipod, then it crashes and I'm forced to restore. Why might this be, and is there some sort of 'soft restore patch' that might be available from

  • PDF arrives is gibberish rather than an attachment

    What makes a PDF arrive not as a file but many lines of gibberish? Below are lines right before the gibberish. Thanks --Apple-Mail-5--14516743 Content-Transfer-Encoding: base64 Content-Type: application/pdf; x-mac-type=50444620; x-unix-mode=0644; x-m

  • Weblogic workshop batch process

    hi all, am new to weblogic workshop. am looking to see how we can start a batch process in wlw (weblogic workshop) that in turn does a few activities like checking for file exsistence from previous application and if not copying it over from the back

  • Mobileme problem med iweb

    Jeg har et site, der var tilknyttet mobileme og lavet i iweb, som jeg nu prøver at udgive via FTP (stadig via iweb), men selvom det ser ud til at virke, er det stadig Apples 'mobileme is closed'-besked, der kommer frem på hjemmesiden. Hvad skal jeg g

  • How to merge two address books?

    I am migrating from a G4 with 10.3.9 to a iMac with 10.5. We want to merge the addressbook with another iMac on 10.5 connected via ethernet. The addressbooks used to be identical but the one from the G4 has fallen out of date. I would like to merge t