SocketChannel problems reading from a non-blocking channel

why when I read a "big" message from the channel (SocketChannel.read(ByteBuffer)) I receive it cutted in more parts?

up

Similar Messages

  • Problems reading from a file

    Hey,
    I have this file that I need to read so i can handle the contents. It was created in MSDOS and as I have very little experience in that topic, I wondered if anyone can point me in the right direction. I tried reading it as a ascii and binary file but neither work, I'm really just guessing though.
    The file has no extension. Hence I can't upload it to the forum. Its made up of mostly meaningless strings of characters.
    Any help is appreciated,
    Regards,
    Rkll

    Rkll wrote:
    Ya you're exactly right, its parsing the data that is the problem. I have done what you said and attached it as a .txt file. My inital thought was that it was a collection of binary digits but I was unable to read them with the built in Labview read binary file VI. Although maybe I had a setting wrong or something.
    This has nothing to do with the Read From Binary File VI, or any setting. That functions does not magically know the format of a file, just like any binary file read for any other programming language. Thus, you have to tell it how to interpret the data. You can tell it to read the file as a series of bytes, and it will dutifully return to you an array of U8 integers. Or, you tell it to read it as a series of 16-bit integers and it will dutifully return to you an array of I16. It will give you what you tell it to give you. 
    Looking at the file I can see some header information, though it's not clear what all the spaces are being used for. I can't tell whether they're padding for a section, or what. As I noted, do you have any idea as to the format of the file?  You said you're updating an old computer system. Any documentation?

  • Read Timeout on non-blocking sockets

    Hi,
    I was wondering if there is a way to specify a read timeout (like setSoTimeout for synchronous sockets) when using a non-blocking socket.
    I'd like to have the select() method return is a sockets timeout expires, puting in the selected key set the timedout socket and have it's read operation return -1, something like what happens when a socket is closed by the other side.
    The thing is I need this to be a timeout specific to each socket, thus the select(millis) isn't apropriate.
    Anyone knows of something like this?
    Thanks....

    Yeah, select() is the only thing built in for that, and you have to do the bookkeeping yourself. You would start something like forming the disjunction of the ready keys and the registered keys after each select, to get the unready keys, and then looking at their history to see how long they have been unready via a Map{key,Long(time)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problem reading from xml

    So this is the thing: I have a regular xml file I want to
    read from flash, locally it works as it should, when I upload it
    things go wrong. Nothing seems to happen.
    If I use the safari activity window it shows me the xml file
    is either "forbidden" or "method not allowed". I already changed
    the permissions on all the files, still nada...
    I have no clue as to why is this happening, I'm leaving a
    copy of all the files here
    http://www.aquigorka.com/files.zip,
    but I said locally it works, the problem is online. If any of you
    have any ideas to figure out what's happening I'd appreciatte it.
    Cheers
    Gorka

    Let me clear a few things:
    It works offline as it should:
    A flash movie calls a static method from a class to bring
    data from a database.
    Usually I don't read from xml, I read from php (that is whay
    I need the sendandload method), but to debug I transformed the php
    into xml because I couldn't figure out what was causing the
    problem.
    So far, I think the problem is the sendandload method: if I
    change the method to just load it works fine (offline and online),
    if I turn it back to sendandload it just won't work online (offline
    it works smoothly).
    I know the onLoad action is being triggerred as it should,
    but the xml object is empty (why?), I'll try and see if the
    security settings have something to do with this.
    Any other suggestions will be appreciated.
    Thanks for the help so far, but I haven't found the answer
    yet.
    Cheers
    Gorka

  • Problem reading ' from XML uisng SAX Parser

    Hi All,
    I have a XML which contains the following element
    <DataText>This is simple ' Text</DataText>I have included & apos ; in the element called DataText.
    When parsing the element, am getting only the text that appears before & apos ;
    When Not including & apos ; am able to get the full text from this element.
    I observed that in the method characters(char buf[], int offset, int len)
    Thelen attribute shows the total length from start position to the position where & apos ; starts...
    How can i get the whole text which includes even " & apos ; "
    Thanks
    Note : while posting this request, & apos; is being formatted to ' . thats the reason included space between them

    HI,
    Was not doing much in the characters method, anyway here is the code
    public void characters(char buf[], int offset, int len) throws SAXException{
        elementText  = new String(buf, offset, len).trim();
    }The value for len is from the start position of the element value and the start position of the ' & apos; ' in the XML File...
    If i remove the ' & apos; ' in the element value , then the len is the full character length in between the element.
    Very confused why this is happening !!
    Did anyone face this problem ever before ?

  • Problem reading from file

    Hi,
    im bit new to java and i am having this problem. I have a Hashtable of 42000 keys and each value points to an object (vector of arrays). I am storing this hashtable to a file using ObjectOutputStream. the file size is 25 mb. no problem till this point.
    I am using ObjectInputStream for reading this object from the file. file is loaded successfully but it takes too much time (1 min to load 25mb file). is there a way to improve the function so it wont take that much time. here is my read function
    try{  
    FileInputStream f_in = new FileInputStream ("data.dat");
    ObjectInputStream obj_in = new ObjectInputStream (f_in);
    Object obj = obj_in.readObject (); // here is the problem. obj_in.readObject() takes 1 min to load
    if(obj instanceof java.util.Hashtable){
    Hashtable idx1 = new Hashtable();
    idx1 = (Hashtable) obj;
    return idx1;
    else{
    System.out.println("loading failed!");
    catch (Exception e)
    System.out.println (e.toString ());
    }

    it still taking that much time.
    the problem is here
    Object obj = obj_in.readObject ();
    Are you saying you do not gain any time at all using a buffered stream?
    In any case, there is no way (I know of) to improve the execution time of deserialization itself. What needs to happen, i.e. reading a lot of bytes from a file + re-constructing a lot of objects, needs to happen. Often disk access will turn out to be a bottleneck; using a buffered stream to the file can improve the speed of this part. But the object reconstruction can not be improved. You could profile your application to find out where exactly the bottleneck is, but I don't see how you can speed it up even if you do know if it's disk access or reconstruction.
    If there is a way to speed up the reconstruction process during deserialization, I'd be very interested to know how, actually.
    If the runtime is simply unacceptable for your requirements, you might consider looking into using something else then Java serialization to write/read your data.

  • Problems reading from bound shared variable

    I have a shared variable that is bound to another shared variable.  When I go to read it's value in a VI by wiring the variable to the "value" property of a digital numeric object it displays zero.  When i look at the two shared variable in the variable manager they show the correct values.  Does anyone have a clue what's going on?

    Welcome to the forums!
    Let's narrow down the possibilities here.  Try wiring the shared
    variable directly to a front panel indicator rather than using a
    property node.  Second, the shared variable object includes an
    error out terminal - this is where the variable engine can report any
    errors in obtaining a value from the bound item.  Wire the error
    out to an error handler VI and re-run - you may find that the Shared
    Variable Engine is reporting an error, which would be most helpful in
    determining the problem. 
    If you could let me know the results of the above suggestions, I'll be glad to help further!
    Cheers,
    Matt Pollock
    National Instruments

  • Problem reading from the screen of Adobe Reader XI

    Hi,
    Since I installed Adobe Reader XI, I cannot no more reading the documents from the screen.  Here is what I see:
    I get this message from Adobe:
    I'm following the above instruction I don't see any such option as "Enable Protected Mode". 
    I'm not sure even if this is the cause of the above problem.
    Please help,
    Chanan

    Your top image seems to indicate you may have a computer virus on your system. I highly recommend you run a virus checking program on your computer, download the latest virus definitions and hope that they can remove the infection.

  • Problem switching from a non Idea Exchange board to an Idea Exchange board when typing a new post

    Tested on Chrome/XP and IE8/XP
    when I start a post in a non Idea Exchange forum and later on want to convert it into an Idea Exchange one, I can switch to the correct forum using the "Select Board" pull-down list. However, when posting, my post is refused because I haven't chosen a "Label". Well, that's because I can't!
    In other words, switching to an Idea Exchange board does not add the "Label" options on the composition webpage, hence it is impossible to post that idea unless you copy it (or rely on the autosave function), start a new post directly into a Idea Exchange forum and paste your old post in it (or alternatively, load the saved draft once you have created the new post).
    Disclaimer: this may have already reported, but as I said elsewhere, the Search function doesn't work either...

    This is my first post so be gentle with me.  I have a Pixi Plus running os 1.4.5.  Last week we upgraded to exchange 2010 (or 14 as I've heard it called).  I lost the connection on my phone.  I tried changing the inheritable permisions above and it has not solved it.  I'm pretty sure all the log in info I'm using is correct.  It acts like it's communicating with the server because it says
    Unable to sign in
    Could not sign into account
    THe mail server responded: bad login/password
    I've changed several things and when I change certain things it says it cannot validate incoming mail server so I feel like I'm close but can't figure it out.  Any help would be appreciated.  Thank you.

  • Reading from a non-HTTP socket in WL; same idea as WL.system.listenPort

    Hi Fellow EJBers,
    I have a system which must listen on a TCP port that is not the normal
    WebLogic port nor the standard HTTP port for client connection
    requests. Unfortunately, the protocol is low-level TCP/IP sockets and
    as it's coming from a legacy system I cannot change. What I'd like to
    do is create a startup class in the EJB server that listens to the
    correct port and then hands off the socket ID to a bean for further
    processing. Then when the response is ready I can use a simple socket
    write() method.
    I am hoping that this will allow me to use WebLogic's built-in threading
    support in this class. I was hoping to find some way to imitate the
    WebLogic properties file entry
    weblogic.system.listenPort=7001
    but I didn't see any references to it in the documentation. Can I use a
    servlet or startup class to do this? I don't want to use events if I
    can help it to maintain compatibility. Alternatively, I'm thinking
    about using a separate Java process running in a different JVM which
    would manage the threading issues. This is less desirable because it
    complicates sending responses back and I don't know if I can pass the
    socket reference into EJB.
    Note that right now I'm only worrying about the listening portion, I
    must also send requests out to different machines but here I control the
    initiation.
    Thanks for any and all help,
    Terry ([email protected])

    Rob,
    Could you please explain why you should not create worker threads in the server.
    I created a GenericServlet and installed it in the ServerClasses so it does not
    ever get more than one instance - it listens on a server socket (in a thread) and
    accepts connections and allows replies to the
    connected socket. I use it for debugging where you connect to the port with Telnet and
    each developer that wants to output a debug string from a JSP back to their Telnet can
    do so. It works fine.
    I don't want to screw the server up so please enlighten me.
    Joe
    Rob Woollen wrote:
    If you have a legacy system that is sending data over TCP/IP sockets, you have
    to have a socket for it somewhere. It's certainly not an ideal situation since
    WebLogic already provides these basic services for you, just not for an arbitrary
    protocol.
    You definitely should not create worker threads in the server. Use WebLogic
    events or JMS instead.
    -- Rob
    Rob Woollen
    Software Engineer
    BEA WebLogic
    [email protected]
    Russell Castagnaro wrote:
    Rob,
    Is it OK to start your own threads that listen on a particular port? I've been
    informed over and over again that this is a recipe for disaster. If it is
    acceptable to start up a port listener thread at some times, when is it
    acceptable and when isn't it? (I know not to do it with Servlets or EJB's)
    Thanks in advanced..
    Russell
    Rob Woollen wrote:
    Hi.
    Terence Davis wrote:
    Hi Fellow EJBers,
    I have a system which must listen on a TCP port that is not the normal
    WebLogic port nor the standard HTTP port for client connection
    requests. Unfortunately, the protocol is low-level TCP/IP sockets and
    as it's coming from a legacy system I cannot change. What I'd like to
    do is create a startup class in the EJB server that listens to the
    correct port and then hands off the socket ID to a bean for further
    processing. Then when the response is ready I can use a simple socket
    write() method.
    Okay, that seems reasonable. Note, that EJB 1.1 (the next version of
    the spec) prohibits bean writers from directly reading or writing sockets.
    I am hoping that this will allow me to use WebLogic's built-in threading
    support in this class. I was hoping to find some way to imitate the
    WebLogic properties file entry
    weblogic.system.listenPort=7001
    but I didn't see any references to it in the documentation.I'm not sure that I follow. You could use your own properties file if
    you want to configure a listen port for your socket.
    Can I use a
    servlet or startup class to do this? I don't want to use events if I
    can help it to maintain compatibility.JMS (available in 4.5.x) is a J2EE standard tha has a superset of the
    events functionality.
    Alternatively, I'm thinking
    about using a separate Java process running in a different JVM which
    would manage the threading issues. This is less desirable because it
    complicates sending responses back and I don't know if I can pass the
    socket reference into EJB.
    Note that right now I'm only worrying about the listening portion, I
    must also send requests out to different machines but here I control the
    initiation.
    Thanks for any and all help,
    Terry ([email protected])
    Russell Castagnaro
    Chief Mentor
    SyncTank Solutions
    http://www.synctank.com
    Earth is the cradle of mankind; one does not remain in the cradle forever
    -Tsiolkovsky

  • Problem reading from file, please help me.

    i have a file named test.txt like this.
    12 321
    13 321321
    11 421
    10 421
    1 4253
    6 3214
    3 4214
    1 46543
    4 5435
    5 54353
    1 5435
    3 7654
    im trying to write a class that has a method which returns a String[12][2] .
    The String should be like this:
    String[0][0] = 12
    String[0][1] = 321
    String[1][0] = 13
    String[1][1] = 321321
    here is my class
    import java.io.*;
    public class Reader{
         public Reader (){
         public String[][] readfromFile ()     {     
              int nreg = 12;
              int i=0;
              int j=0;
              int quebra = '\n';
              int ent=0;
              BufferedReader reader;         
              String[][] saida = new String[12][2];
              char[] cod = new char[5];
              char[] cod1 = new char[5];
              try     {     
                   FileReader file = new FileReader("test.txt");
                   reader = new BufferedReader(file);
                   while (i<nreg) {
                        while(ent != ' ') {
                             ent = reader.read();
                                cod[j] = (char) ent;
                             j++;
                        saida[0]=String.valueOf(cod) ;
                        while (ent != quebra) {
                             ent = reader.read();
                             cod1[j] = (char) ent;
                             j++;
                        saida[i][1]=String.valueOf(cod1) ;
                   i++;
              catch (IOException ioe)     {                 
                   System.out.println ("I/O Exception occurred!");      
         return saida;
    Im getting problem with while and dont know how to deal to make my program runs fine.
    My static void method is in another class
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    public class exe2{
         public static void main(String args[]){
              String[][] saida = new String[12][2];
              try {
                   Reader teste = new Reader();
                   saida = teste.readfromFile();
              catch(Exception e){
                   System.out.print(e.toString());
              for (int i=0;i<12;i++)
                   System.out.println(saida[0]);                
    Any help is really apreciated

    I have modified this class, but i still have problems
    import java.io.*;
    public class Reader{
         public Reader (){
         public String[][] readfromFile ()     {     
              int nreg = 12;
              int i=0;
              int j=0;
              int quebra = '\n';
              int ent=0;
              BufferedReader reader;         
              String[][] saida = new String[12][2];
              char[] cod = new char[10];
              char[] cod1 = new char[15];
              try     {     
                   FileReader file = new FileReader("test.txt");
                   reader = new BufferedReader(file);
                   while (i<nreg) {
                        j=0;
                        while(ent != ' ') {
                             ent = reader.read();
                                cod[j] = (char) ent;
                             j++;
                        saida[0]=String.valueOf(cod) ;
                        j=0;
                        while (ent != quebra) {
                             ent = reader.read();
                             cod1[j] = (char) ent;
                             j++;
                        saida[i][1]=String.valueOf(cod1) ;
                   i++;
              catch (IOException ioe)     {                 
                   System.out.println ("I/O Exception occurred!");      
         return saida;
    I see that there is a problem with cod1 because when i run this class
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    public class exe2{
         public static void main(String args[]){
              String[][] saida = new String[12][2];
              try {
                   Reader teste = new Reader();
                   saida = teste.readfromFile();
              catch(Exception e){
                   System.out.print(e.toString());
              for (int i=0;i<12;i++)
                   System.out.println(saida[0]);                
    I hava an arrayoutofbound exception 15 and displays null null null ....
    any hint?

  • Timeout Problems reading from Agilent 53151A Counter

    Hello again:
    I'm having a problem programming the Agilent 53151A counter. For some reason, the timeout error (code -1073807339) would always pop up at the end of the VI execution. The error occurs in the VISA Read part of the VI. I've placed a 20 second timeout in the VI, but I'm still having trouble reading it.
    I find it incredibly frustrating because the same VI was working well a couple days ago. Now I can't get the thing to read.
    It's not a communications problem because it says on the counter that it's being controlled remotely (which is through the GPIB).
    I've attached a copy of the VI if you want to see the problem.
    Attachments:
    53131ReadFrequency.vi ‏80 KB

    There's a couple of things you might want to try. First, I would take out the VISA Clear before you run it every time. The clear operation may not be complete by the time you issue the measurement command so the instrument might not be receiving it and you'd have nothing to read back - causing the read timeout. The other thing is the triggering status of the counter. If its set to trigger on some level and the signal's not there, you might not get anything back. There is also a driver for the instrument available. You can find it here. It uses the traditional GPIB commands instead of VISA but it's pretty easy to modify.

  • Problems reading from / writing to files in C on XCode 3

    Hi all,
    I'm a newcomer to C, having been learning for about a week and a half. All going well so far.
    I'm working through Dave Mark's 'Learn C on the Macintosh' e-book, and am up to Chapter 10, 'Working with Files.' Herein lies the problem.
    I can't get any of the file-related commands to work. The most basic, it seems, is 'fopen()'. There's a very simple demo program which is supposed to open an accompanying file ("My Data File.txt") which is in there with main.c and so on. Nothing happens, though. I've tried it with a 'w' mode parameter which should create the file if it doesn't already exist, but Spotlight can't find it if it is indeed being made.
    I'm using a fairly vanilla install of XCode 3, so I shouldn't have messed up the settings anywhere along the way. I've tried all of the different path types in the 'Get Info' dialogs, but still nothing.
    I guess that it's something very basic that I've missed or not understood. If any of you could take the time to help me out, it'd be much appreciated.
    If there's any further information you need, please just let me know.
    Many thanks,
    Pete.

    Ok I'm new to c programming and xcode and I have this same problem but the suggestions have not remedied my problem. I get this warning:
    "warning: no rule to process file '$(PROJECT_DIR)/operations.txt' of type text for architecture i386"
    This is my code
    #include <stdio.h>
    #include <math.h>
    int main()
    char filename[128],fvalue1[128];
    int x=0;
    FILE *input;
    printf("Enter name of file: ");
    fgets(filename,128,stdin);
    if((input = fopen(filename,"r"))==NULL)
    printf("Failed to open file.\n");
    x=1;
    if(x!=1)
    fgets(fvalue1,128,input);
    fclose(input);
    fflush(stdin);
    printf("\n\nPress enter to continue...");
    getchar();
    return(0);
    I think its a setting but I dont know what else to try.
    Any further input on this would be greatly appreciated. thanx

  • Non-Blocking SocketChannel read give Connection timed out

    Hi,
    My program is using Non-Block NIO SocketChannel for both Server and Client sides. However, if the connection between server and client has been idle for a while, when the client try to communicate with server, it gets blocked for a while (15 minutes) and then receives the following exception:
    java.io.IOException: Connection timed out
         at sun.nio.ch.FileDispatcher.read0(Native Method)
         at sun.nio.ch.SocketDispatcher.read(Unknown Source)
         at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
         at sun.nio.ch.IOUtil.read(Unknown Source)
         at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
    How can this be since the read is in Non-Blocking mode? Also, is there anyway to determine the timeout without being blocked?

    This would mean that you are trying to read from the socket without having properly completed the connection, which timed out. I would say you are connecting in non-blocking mode but not calling finishConnect() when you get OP_CONNECT.

  • Non-blocking SocketChannels

    I'm trying to learn how to use non-blocking socket channles, but I haven't found much info (nor luck) so far.
    To learn, I'm building a server and a client. The server accepts input from the clients and process it in only one thread. The clients should send Objects to the server, and the server process them and return the result also as an Object. For this, I'm trying to use ObjectOutputStream and ObjectInputStream.
    The problem I don't know how to solve is that the SocketChannel is in non-bolcking mode, so I can't use their input/output streams (I get a IllegalBlockingModeException). In the server process loop I can reconfigure the SocketChannel to blocking mode to be able to read the Object, but I can't configure it to non-blocking mode again because I get a CancelledKeyException.
    Does anyone know how to work with InputStreams and non-blocking channels? Or where to find more info about it?
    Here are the relevant part of the server code:
    Set ready = selector.selectedKeys();
    Iterator i = ready.iterator();
    while (i.hasNext()) {
       try {
          SelectionKey sk = i.next();
          i.remove();
          if (sk.isAcceptable()) {
             ServerSocketChannel ssc = (ServerSocketChannel)sk.channel();
             SocketChannel sc = ssc.accept();
             sc.configureBlocking(false);
             sc.register(selector, SelectionKey.OP_READ);
          } else if (sk.isReadable()) {
             SocketChannel sc = (SocketChannel)sk.channel();
             // PROBLEM: If the channel is in non-blocking mode
             // I cannot use InputStreams
             sk.cancel();
             sc.configureBlocking(true);
             // Read the object sent by the client
             ObjectInputStream in = new ObjectInputStream(Channels.newInputStream(sc));
             Object o = in.readObject();
             // PROBLEM: Can't put the channel back to non-blocking mode
             sc.configureBlocking(false);
             sc.register(selector, SelectionKey.OP_READ); // CancelledKeyException
       } catch (...){
    }

    In my client, this is working fine:
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
    for (int i = 0; i < 30000; i++) {
       oos = new ObjectOutputStream(sc.socket().getOutputStream());
       oos.writeObject(object);
       oos.flush();
       ois = new ObjectInputStream(sc.socket().getInputStream());
       Object o = ois.readObject();
    }But trying to do it like this throws a StreamCorruptedException at the server side.
    ObjectOutputStream oos = new ObjectOutputStream(sc.socket().getOutputStream());
    ObjectInputStream ois = new ObjectInputStream(sc.socket().getInputStream());
    for (int i = 0; i < 30000; i++) {
       oos.writeObject(object);
       oos.flush();
       Object o = ois.readObject();
    }Do you know why?

Maybe you are looking for

  • View (or filter) document library items by Groups

    Hello I have a bunch of documents in a library. I would like specific groups to see specific documents. For example, Group 1 can read Document A and Group 2 can read Document B but Group 1 and 2 should be able to read Document C. Some of the groups c

  • Getting BPM Deployement Exception

    Hi Experts, can you please help me in resolving the below issue we are getting while deploying the BPM. I have created the split mappings in PI and imported to BPM. While importing no issues occured . But while deploying  we are getting below error.

  • Failed to retrieve a schema URI (document namespace) for /userprofiles/emailNotification.usr; please see the following exception for details

    I get this exception (and long stack trace) when attempting to start my weblogic server. I'm running Weblogic 7 with Portal 7 (sp 1). I'm using Oracle 8.1.7. I upgraded this application from weblogic portal 4.0, and never had this problem there. As p

  • F-54 Add column BLDAT into Item data

    Is it possible to append the field BLDAT (from Header) into Item data? 1.Enter f-54. You see screen 114 programm 2. Then fill in the obligatory fields and push button ENTER. 3.Now you see the table Down Payments - screen 1703. I need to add a new col

  • How to test if an external file is already opened?

    We have an issue when we write to an external file via the DBOpen and DBAdd functions. When we run two jobs simultaneously, they write to the same file. I know we can write to separate files, but we rather not. When the second job begins to do the wr