Reading unknown number of bytes !

Hi all !
I am trying to read unknown number of bytes from the socket.Meanwhile I need to process the bytes depending on the message type in the header.I get messages like this header,body,header,body header,body header,body.....the message type is specified in the header.Each message type has different body size.So depending on that I have to read the next few bytes from the socket....say 300 or 600 depending the on the message type in the header.I get the bytes continioulsy like this.Since I cannot read byte by byte due performance reason is there any other way to do that.....any help will appreciated
sash

A simple workaround is to use a java.io.PushbackInputStream
Read enough bytes to get the header, parse the header bytes, and push the remainder back into the stream to be read as the body.

Similar Messages

  • Reading unkown number of bytes

    Hi all !
    I am trying to read unknown number of bytes from the socket.Meanwhile I need to process the bytes depending on the message type in the header.I get messages like this header,body,header,body header,body header,body.....the message type is specified in the header.Each message type has different body size.So depending on that I have to read the next few bytes from the socket....say 300 or 600 depending the on the message type in the header.I get the bytes continioulsy like this.Since I cannot read byte by byte due performance reason is there any other way to do that.....any help will appreciated
    sash

    Assuming you have a consistent header size and format, you can just read that in one call. I prefer sticking the size of body in the header. That way I can pluck that value out of the header and use it for the next read.

  • TCP Read undifined number of bytes

    Hello LabVIEW RT users
    I'm trying to convert a java application to my LabVIEW RT Smart Camera
    In my camera I have a working TCP server which reads and writes some data to/from a robot. My problem is that in LabVIEW i have to specify who many bytes I'm reciving to get it to work. But in my Java application the BufferedReader took care of this. I can't control what the robot is sending but it could be things like these strings
    GET X
    SET R 1
    SET X 443
    SET X 11
    GET START
    Somone who knows how I best handle this problem? I have tried to change the mode of the TCP read to CRLF but without succes

    If you have 1MB if random binary data, is highly likely that there will be a CRLF embedded somewhere by chance, so that won't work. None of your vague comments and suggestions make any sense so far. This is most likely a very simple problem that you are way overthinking and trying to overengineer. Billions of bytes of variable lenght data are transmitted every second across the world and nobody else seems to have these problems.
    Please be more specific about your application:
    Where is the data coming from?
    Is it also LabVIEW and do you have control over the sending program?
    How easy is it to tell if it is binary or formatted?
    Can you tell from the data pattern once an entire set is received?
    how long are the pauses between datasets?
    What happens to the data after it is received? (stream to disk, scan, parse, etc.)
    LabVIEW Champion . Do more with less code and in less time .

  • How to get the number of bytes at TCP port

    Hi all,
    How to get the number of bytes to read at the TCp port...as someone had suggested in some forum we do read the number of bytes first and then pass this...
    but we get a problem when we have FF data in this...because then it sends 2 FF data...and cause of this we skip the last data...is there any solution for the same?

    Hi
    In LabVIEW you don't have the same property as in serail port.
    You havn't "Byte at TCPIP port".
    if you developp a protocol, one soltion, is to send the size to read.
    Ingénieur d'Application / Développeur LabVIEW Certifié (CLD)
    Application Engineer / LabVIEW Certified Developer (CLD)

  • Smsy "Read System Number" customer number unknown for installation

    Hi gurus,
    I 'm configuring SMSY and following the steps outlined in the IMG in the basic settings and trying to configure RFC connections to/from satellite systems. In SMSY, I have 2 systems configured SMA and BIF.
    tcode SMSY-> Systems -> SAP ERP -> SMA , Tab "System Data in SAP Support Portal".
    Click "Read System Number" returns error SAP customer number unknown for installation number 0020179718. <-Why?
    Click "Installation Data" shows data from SMP with correct installation number and correct customer number 706822.
          The S-user listed under "Contact Persons" is not mine, not the correct one. <- Why? How to fix?
          The system number from SMP matches value in System Number field.
    Click "System Data" shows data from SMP also shows correct data.
    Why unable to "Read System Number" when the correct system number is read via "Installation Data" and "System Data"?
    tcode SMSY->Systems->SAP ECC->BIF, Tab "System Data in SAP Support Portal".
    Click "Read System Number" returns error "SAP customer number unknown for installation number 0020472810". <- Why?
    Click "Installation Data" shows data from SMP with correct installation number and correct customer number 706822.
          The S-user listed under "Contact Persons" is correct one.
          The system number from SMP matches value in System Number field.
    Click "System Data" shows data from SMP also shows correct data.
    Why unable to read system number?
    When I login to SMP with same S-user, under System Data Maintenance, the same data is displayed as in "Installation Data" and "System Data" links.

    I don't know what happened. I came into work today and tested the "Read System Number" and it worked. I read thru the 2 notes you mentioned, just read now. The first notes I had already followed before opening this thread. The 2nd notes also talked about turning off BAdI implementation AI_SDK_SP_RFC_RP, of which I did a couple of days ago before opening this thread. I had turned turned off BAdI and simplified the AISUSER table and removed the customer number field, in order to get back to the "single-user number" basic setup in the IMG.
    I had found the problem with the wrong contact info on the SMA system. It was wrong in the SMP system maintenance under installation data.
    Thanks for your help.
    -Don.

  • Easily read strings while tracking the number of bytes read?

    Hi all,
    I'm after a way to easily parse and read strings from a file, while also being able to check (at any point) how many bytes have currently been read from that file.
    I currently use the following for the string processing:
    BufferedReader in = new BufferedReader(new FileReader(filename));
    String str = null;
    while ((str = in.readLine()) != null)
      // process the string
    }That's all fine, but the files I'm reading can be very large (multi GB) so obviously it can take a while to read them. During this time I pop up a progress bar, and attempt to track the progress of the read. The files I'm working with just now come with a header on the first line that states how many "somethings" (that I happen to be looking for) will appear in the file. I can use that number to set the maximum value for the progress bar, and update its current value as I find them.
    However... I'm also about to start working with files that don't contain this information. I've thought of two ways of knowing how much work has to be done in advance of the read so the maximum value for the progress bar can be set:
    1) Quickly count the number of lines in the file without doing any processing. This works, but can still take some time for large files, even with more efficient reading algorithms.
    2) Use File.length() to set the maximum to be the number of bytes that will read.
    I'd like to use 2), but can't work out a way to use simple String based file parsing (as in the code above), but also be able to know how many bytes have been read so far. Using this code means I don't have to worry about end of line terminators, charset encoding, etc - the Reader does it for me.
    Any suggestions?
    Thanks

    import javax.swing.*;
    Component parent; // might be null, or your JFrame
    String message; // message to display in the progress bar
    BufferedReader br = new BufferedReader(new InputStreamReader(new ProgressMonitorInputStream(parent, message, new FileInputStream(file)), charset));

  • How do I write and read a specified number of bytes using C++?

    I need to send one byte commands followed by 1 or 2 byte data as well as read 1 or 2 byte commands from a RS232 device. How do I ensure that only 1 byte is sent for the commands or 2 bytes of data using VISA?

    Hey BMas05,
    Using VISA in C++ you can strings or bytes depending on which polymorphic version of the write you are using. One of the parameters for the VISA Write is the byte array and the number of bytes. This is if you are using the VISA classes for C++. You might have to have Measurement Studio to get these classes.
    There is a really good example that installs on your computer at C:\Program Files\National Instruments\MeasurementStudio\VC\Examples\Io\Visa\Serial Visa.
    This example shows how you can write just bytes or strings and you can select how many bytes to read back.
    I hope this helps out.
    JoshuaP
    National Instruments

  • ORA-27063: number of bytes read/written is incorrect

    Hello -
    I am getting this error because my filesytem is at 100%:
    ORA-01114: IO error writing block to file 202 (block # 423324)
    ORA-27063: number of bytes read/written is incorrect
    However, when I query the dba_data_files, and v$datafile views, I do not see a reference to file 202. Where can I get this information?
    Thanks,
    Mike

    Mike,
    Looks like you got a solution, however, just FYI, tempfiles are numbered starting w/ db_files+1, so, likely, your value of db_files is 200, the error occurred on your number 2 tempfile.
    -Mark

  • TCP/IP Read - How do I find the number of bytes available

    It appears that this is not directly possible. I am trying to get around
    this by doing a tcp/ip buffered read with a very short timeout (0 or 1ms).
    In theory it seems like I should be able to keep making the read call until
    the exact number of bytes (4 in this case) pops out. It mostly works but
    every so often hangs for some period of time and then resumes getting the 4
    byte packets. Anybody have any idea what is going on?

    The first thing I'm thinking of is that your delay is too short. Also, try to increase the packet length or use Immediate Mode (even CRLF MODE if you're transmitting text).
    Another idea (if your application really needs that and you have LV / Windows) is to use MS Winsock Control (wait for DataArrival event and read BytesReceived).
    Anyway, tune in your communication (packets and delays) taking in account details about your network or modem.
    Good luck!

  • Length specified in network packet payload did not match number of bytes read; the connection has been closed.

     Hello every one
    I am getting this in my event log from time to time . not sure what is that ?
    Is this a hacker trying to send rubbish data to SQL through the port ?
    Any help is appreciated .
    Length specified in network packet payload did not match number of bytes read; the connection has been closed. Please contact the vendor of the client library. [CLIENT: someip]

    Thank you all for the reply  , 
    my server is on port  1533 . Port  1433  is closed  on my server .
    All the requests are coming from my own ip , i feel this is funny . 
    Is my server hacked then ? 
    Or could be my ISP doing any routine tests ? 
    Also is this is hack attempt , what does this hacker think he will benefit from this ? Could this bring the SQL  server down  ?  
    I was thinking about chaning port to something else ,  1344 or something , u think this can be better  ?

  • Showing dynamic and unknown number of images in SSRS report

    I am using SSRS 2008.  I need to display an unknown number of unspecified images on the report.
    Basically I have a webpage, where the user selects a specific ID (ex. 24) from a dropdown and then click "View Report".
    The report should then display any images, associated with that ID.  The only thing I know about the images, is the path to where the images are stored.  The path is kept in a database, so I should be able to retrieve the path ok.
    But then how do i get the report to display the images, when I do not know the name or number of images?
    Please help.

    Hi dukie4lif,
    According to your description, you have a report to display images selected by users. Now your issue is, the users select a specific ID to get images, but you only have the path of images stored in your database. Is my understanding correct?
    For your requirement, if the users want to get images by selecting a specific ID, this ID must be stored in database and associated with the path of those images. Otherwise the database can never query any records with this ID if it doesn’t have any ID stored.
    Now we need to go to your database, create one more table or add one more column in the table which have your path stored to store those IDs, and let them associated with those path. Use a parameter in this report for users selecting IDs. Then your goal will
    be achieved.
    Reference:
    Report Parameters (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou (Pactera)

  • Add Listener to Unknown Number of JMenuItems

    How can I add an ActionListener to each JMenuItem by cycling through an unknown number of menu items?
    I have a program that prompts the user for a database, then creates a JMenu of table names based on whatever database the user selects.
    This means that I don't know the table names or number of tables that will be added to the JMenu.
    I need to add an ActionListener to EACH JMenuItem. The problem is that I am only able to select one table from the menu. Subsequent menu clicks (on different table names) have no affect on the output.
    Here is an excerpt of my code:
    ResultSet rs = md.getTables(null, null, null, types);
    while (rs.next()) {
    tables.add(rs.getString("table_name"));
    for (Iterator i = tables.iterator(); i.hasNext(); )
    String table = (String) i.next();
    JMenuItem mi = new JMenuItem(table);
    j1.add(mi);
    mi.addActionListener(this);
    [END CODE]
    Thanks for any help you can give!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    I got it. It turns out that I WAS setting the listeners correctly. My additonal output was "hidden" in the window. I found it by pure luck when I expanded the window size.
    I added a line to remove all components from the JPanel before adding a new one and this "refresh" worked.
    Thanks fot the help anyway! It is greatly appreciated.

  • Calls from cucm to CME not working-unknown number

    hi all
    we have cucm 9.1 and gateway 2911 on the side A and on the side B we have uc540 , we have configured tunnels between 2911 and uc540, calls from cucm SideA to uc540 Side B is ok and working fine. now we have one 9951 phone which gets ip from uc540 (side B) and tftp is our cucm IP.9951 phone is registered in cucm and calls from cucm to that 9951 phones are working fine. now problem is call is one sided between uc 540 local extension and ip phone 9951.
    9951 which is registered on cucm can call uc 540 user  but spa 504 phone which is registered on uc540 cant call to cisco 9951 phone gets error "unknown number"
    i am attaching debug voice ccapi inout with this
    kidnly help me to solve the issue ASAP

    here is show voice register all.i am surprised to see dial peer 20002 but there is no dial peer like that i dont know where its getting this dial peer 20002.extension 2002 is registered with my call manager.
    Router#sh voice register all
    VOICE REGISTER GLOBAL
    =====================
    CONFIG [Version=8.6]
    ========================
      Version 8.6
      Mode is srst
      Max-pool is 0
      Max-dn is 0
      Outbound-proxy is enabled and will use global configured value
      Security Policy: DEVICE-DEFAULT
      Forced Authorization Code Refer is enabled
      timeout interdigit 0
      network-locale[0] US    (This is the default network locale for this box)
      network-locale[1] US
      network-locale[2] US
      network-locale[3] US
      network-locale[4] US
      user-locale[0] US    (This is the default user locale for this box)
      user-locale[1] US
      user-locale[2] US
      user-locale[3] US
      user-locale[4] US   Active registrations  : 0
      Total SIP phones registered: 0
      Total Registration Statistics
        Registration requests  : 0
        Registration success   : 0
        Registration failed    : 0
        unRegister requests    : 0
        unRegister success     : 0
        unRegister failed      : 0
        Attempts to register
               after last unregister : 0
        Last register request time   :
        Last unregister request time :
        Register success time        :
        Unregister success time      :
    VOICE REGISTER DN
    =================
    VOICE REGISTER POOL
    ===================
    Router#

  • Output says "The number of bytes in the file are 0" but the file has bytes

    Dear Java People,
    Why would an output say a file has 0 bytes when upon doing a search for the file in Windows Explorer it say the file has 1 -4 kbytes ?
    for example part of my output was :
    "the number of bytes in TryFile3.java are 0"
    caused by the following lines of code:
    System.out.println("\n" + contents[i] + " is a " +
    (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents[i].lastModified())
    + "\nthe number of bytes in TryFile.java are " + myFile.length());
    thank you in advance
    below are the two program classes
    Norman
    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.Date;
    public class TryFile3
       public static void main(String[] args)
           //create an object that is a directory
             File myDir =
            new File("C:\\Documents and Settings\\Gateway User\\jbproject\\stan_ch9p369");
              File myFile = new File(myDir, "TryFile3.java");
            System.out.println("\n" + myDir + (myDir.isDirectory() ? " is" : " is not")
            + " a directory.");
             System.out.println( myDir.getAbsolutePath() +
             (myDir.isDirectory() ? " is" : " is not") + " a directory.");
              System.out.println("The parent of " + myDir.getName() + " is " +
              myDir.getParent());
               //Define a filter for java source files Beginning with the letter 'F'
               FilenameFilter select = new FileListFilter("F", "java");
               //get the contents of the directory
               File[] contents = myDir.listFiles(select);
                //list the contents of the directory
             if(contents != null)
                 System.out.println("\nThe " + contents.length  +
                 " matching item(s) in the directory " + myDir.getName() + " are:\n " );
                 for(int i = 0; i < contents.length; i++)
                   System.out.println("\n" +  contents[i] + " is a " +
                   (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents[i].lastModified())
    + "\nthe number of bytes in TryFile3.java are " + myFile.length());
    else {
    System.out.println(myDir.getName() + " is not a directory");
    System.exit(0);
    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.Date;
    public class FileListFilter implements FilenameFilter
    private String name; // file name filter
    private String extension; // File extension filter
    public FileListFilter(String name, String extension)
    this.name = name;
    this.extension = extension;
    // static boolean firstTime = true;
    public boolean accept(File diretory, String filename)
    //the following line of code can be inserted in order to find out who called the method
    // if(firstTime)
    // new Throwable("starting the accept() method").printStackTrace();
    boolean fileOK = true;
    //if there is a name filter specified, check the file name
    if(name != null)
    fileOK &= filename.startsWith(name);
    //if there is an extension filter, check the file extension
    if(extension != null)
    fileOK &= filename.endsWith('.' + extension);
    return fileOK;

    System.out.println("\n" + contents + " is a " +
    (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents.lastModified())
    + "\nthe number of bytes in TryFile.java are " + myFile.length());I haven't read any of your italicized code, but perhaps there is a good reason why you have "myFile.length()" and not "contents.length()" in this line of code?

  • How to reduce the number of bytes for a picture

    I want to reduce the number of bytes used for a picture to be sent to a site like Ebay or craigslist. I son't see any options in Iphoto for this purpose.

    You can do it in Preview.
    Open the image in Preview. Under Tools, click Adjust Size.
    Scale it down to the smallest acceptable size (the website should give a suggested resolution).
    Then go to File -> Export, save it as a Jpeg.
    Smaller size image means smaller file size.

Maybe you are looking for

  • Will my thunderbolt connect to hdmi to mdp to hdmi?

    hi, i know i cant do minidisplay port to thunderbolt. i have a macbook pro late 2009 and a 2014 21.5" iMac both running osx Mav. Is it possible to do thunderbolt to hdmi and use an hdmi adapter from mdp? Can I connect them this way!??? I tried just u

  • Pairing Apple TV ios6 - cannot get to Apple Support

    The bug in ios6 that makes pairing an iPad with TV impossible is well documented, so I gave up trying and thought to call Apple support for an official line. Of course, they won't give me a number in the UK to call and, when I try to raise a case wit

  • Problem with partition after deleting a bootcamp partition

    Hi everyone ! First, excuse my english, I'm from France. This morning, I've deleted the bootcamp partition I had created weeks ago. But when I've tried to extend the principal partition on the empty space left by bootcamp, the Disk Utilitaire says :

  • Integration between OAF and ADF

    Hi, We have a requirement where we have to call ADF page as a region in OAF page. We are able to deploy ADF application on Web logic server and call them as a standalone application in OAF using "Function and Menu". Also, I understand that ADF and OA

  • IE not filling CS5 UI1.7 MenuBar dropdowns

    Horizontal MenuBar, things working well in Firefox and Chrome.  IE 8 makes only the link active, not the full MenuItem bar -- the background image doesn't change until hovering over the link. Worse, when rolling off the link (down, to get to a lower