Transferring multiple files over a single socket

I'm trying to send multiple files to a client without creating a new socket for each file and I'm undeceided on the best approach. The problem is that if the client is just reading from a socket, it won't know when one file stops and the next begins (assuming that the server side is just writing byte data to the socket). I could use an ObjectStream, but then I can't create a nifty progress bar. I could transfer the byte length of each file so that the client knows how much to read, but this seems messy. Is there a better approach?

Method 1: send file length first. Simple way. Downside: if the file size changes on disk while you are sending it you may be in trouble - what if the file is truncated or there is an IO error so you can't send as many bytes as you promised.
Method 2: use an end-of-file indicator. E.g. "." on a line by itself. If the file contains a "." on a line you'll need to quote it - e.g. the SMTP mail protocol uses "..", and "..." for two periods, etc. Needs a bit of extra code to do the quoting and detecting the EOF marker.
Method 3: send "packets". Send a "packet header" followed by data, e.g.:
HERECOMES C:\fred.txt
DATA 1024 <...1024 bytes...>
DATA 1024 <...1024 bytes...>
DATA 120 <...last 120 bytes...>
END OF FILE HAVE A NICE DAY
You can make the "packet header commands" binary ('\001' = file begins, '\002' = data segment, ...) or sort of human readable like SMTP and HTTP do. The former can be a bit easier to implement, the latter is nice because you can debug it easier and try it out with "telnet".

Similar Messages

  • Hiding filenames when combining multiple files into a single .pdf

    I'm fairly new to this Acrobat X. I'm trying to assemble my portfolio to distribute to employers but I cannot seem to get rid/hide the filenames in the final pdf file. I was using the option to 'combine multiple files into a single pdf' because I was compiling images and documents to a single readable pdf file. I got all that done but once I open it, I'd see that each page would still contain the original file names rather than page numbers - which I prefer not to have employers see for the sake of tidiness (and I refuse to use the Adobe portfolio because it's not really efficient on space or design. I prefer a simple page-by-page pdf). So I was wondering if anyone can tell me how to hide my file names, change them into page numbers or getting rid of them all together so the 'Table of Contents' in the pdf preview mode would not show anything, I would really much appreciate it.
    -Ss

    Well, when the .pdf is in the final, deliverable form; I open it in Mac preview mode and the sidebar is always extended showing a 'table of contents' rather than having each document in the pdf file have a number designating a page name, it shows each individual filename the pdf is composed of. Not too sure about bookmark, though. Thanks for the reply!
    If you want, I can send the file to you.

  • Problems transferring multiple files

    I'm trying to write a program to transfer multiple files from a client to a server, but I'm having trouble getting the server to distinguish between them.
    I have tried both buffered streams, and straight input/output streams, and in both cases, the server doesn't seem to get any EOF, and keeps reading all data it reads into the first file. I can't figure out why EOF is never read (ie: ((read = bis.read(buffer)) != -1) never evaluates to -1). Can anybody see why that might be?
    Client:
    buffer = new byte[16384];
    out    = serverSocket.getOutputStream();
    bos    = new BufferedOutputStream(out);
    objOut = new ObjectOutputStream(out);
    objOut.writeInt(file.length);  // # of files to transfer
    for (int i=0; i<file.length; i++) {
        try {
            fileIn = new FileInputStream(file.getAbsolutePath());
    objOut.writeLong(file[i].length()); // file length (for dirty CRC check)
    objOut.writeObject(file[i].getName()); // file name
    objOut.flush(); // because otherwise the server hangs waiting
    while ((read = fileIn.read(buffer)) > 0) {
    bos.write(buffer, 0, read);
    bos.flush();
    catch (Exception e) {}
    Server:
    in = socket.getInputStream();
    objIn = new ObjectInputStream(in);
    bis = new BufferedInputStream(in);
    fileCnt = objIn.readInt();  // # of files to be transferred
    for (int i=0; i<fileCnt; i++) {
        totalLen = objIn.readLong();  // file length
        try { fileName = (String)objIn.readObject(); }  // file name
        catch (Exception e) {}
        try { toFile = new FileOutputStream(new File(fileName)); }
        catch (FileNotFoundException ex) {}
        while ((read = bis.read(buffer)) != -1) {
            toFile.write(buffer, 0, read);

    the problem is you are not stoping the writing to file when you hit the end of one file.
    At the server you should count the number of bytes that you write to the disk and should stop when the total count reach the file size.
    Or you have to completly change your protocole to handle entire file as one unit.
    Ex:-
    public class MyFile implements java.io.Serializable{
    String path;
    private void writeObject(ObjectOutputStream oos){
       oos.defaultWriteObject();
       byte b[] = new byte[1024*128];
       int i = 0;
       FileInputStream fis = new FileInputStream(path);
       while ((i = fis.read(b)) >=0){
          oos.writeObject(trim(b,i));
       fis.close();
       oos.writeObject("EOF");
    private byte[] trim(byte b[], int i){
        byte b2[] = new byte;
    System.arraycopy(b,0,b2,0,i);
    return b2;
    // You should be able to write the read object method

  • Insert multiple files onto a single track, not one file per track

    Hello,
    In both Audition CS5.5 and CS6, when the user inserts multiple files into a multitrack session, they are placed on multiple tracks. (As the help file says, "The files are inserted on separate tracks at the current time position"). Please change this to allow multiple files to be inserted onto a single track.
    I can understand the usefulness of the current behaviour in some scenarios, but there are other workflows in which the placement of multiple files on multiple tracks is a serious hindrance.
    E.g. In this thread, a user mentions needing to insert 10,000 individual files for dialogue editing and mixing.
    I also posted in that thread because my own workflow involves editing hundreds of individual files, which are single notes recorded for the production of virtual instruments.
    The reason why a "one-track multitrack" workflow is useful to me is that it allows great flexibility in processing multiple files individually or at once, comparing them, adding markers, fades, etc.
    It would also be useful when bringing in any audio that has been recorded in consecutive chunks - field recordings, concerts, Foley sessions, etc.
    In the thread, another user suggested inserting all the files onto a single track in Premiere Pro, then bringing that project into Audition as a multitrack session. Unfortunately this creates another problem for me, because it renames all the audio with the suffix "extracted". My workflow requires me to keep the original file names, because these are used downstream when mapping the recorded notes in the virtual instrument.
    Thanks for reading and please consider this for a future update.

    Just curious. Has there been an answer yet as to how to insert existing audio clips from a file to a waveform view in CS6. I create voiceovers or edit large interview files that require audio tones and sfx for my clients in production studios. The tones are inserted between takes as a courtesy tone to denote separation.  In the older versions of Audition, the function was as simple as mix/pasting an audio file, selecting insert or overlap, set the import level percentage and paste.  And each time this function was exercised, Audition would use the same settings you last used to reduce repetition of settings. Logical. That's all gone in CS6 ... so, to lay down a voiceover file for Comcast or any client, in waveform view (vs. Multitrack which is not necessary for single mono file editing) I have to go through unnecessary steps simple to select insert/mix paste>file>paste into existing wave form.
    Also, if I need to simply overlap a gasp over the last syllable of a phrase in a simple wave form, I don't appear to be able to do this.  I called Adobe for support on these function, but, they had not answers and simple said I couldn't change the workspace, and they had no other answers. Any help would be greatly appreciated if you have insight.

  • Problem trying to transfer multiple file over a network or the internet

    Hello I'm trying to make a file transfer program to transfer file over the internet or a network. I've been able to successfully transfer one file but when I try to send multiple files I keep getting a EOFException after the client trys to send the files. The client says it sent both files and the connection was closed but the server said that it only received one file and throws a EOFException. I've included the code from the client and the server. Any help is much appreciated.
    The Client
    private class createSocket implements Runnable {
              String address;
              int port;
              public createSocket ( String address, int port ) {
                   this.address = address;
                   this.port = port;
              public void run() {
                   try {
                   postStatusMsg( "Opening Connection at " + address + ":" + port );
                   Socket socket = new Socket( address, port );
                   postStatusMsg( "Connected to " + address + ":" + port );
                   DataOutputStream dos = new DataOutputStream( socket.getOutputStream() );
                   DataInputStream dis = new DataInputStream( socket.getInputStream() );
                   dos.writeInt( files.length );
                   for ( File f : files ) {
                        BufferedOutputStream out = new BufferedOutputStream( dos );
                        BufferedInputStream in = new BufferedInputStream( new FileInputStream(f) );
                        postStatusMsg( "Sending: " + f.getName() );
                        byte[] b = new byte[8192];
                        int read = -1;
                        dos.writeUTF( f.getName() );
                        while ( ( read = in.read( b ) ) >= 0 ) {
                             out.write( b, 0, read );
                        postStatusMsg( "File Sent" );
                        in.close();
                   dos.close();
                   postStatusMsg( "Closing Connection" );
                   socket.close();
                   postStatusMsg( "Connection Closed" );
              catch( IOException e ) {
                   Main.ShowMsgBox( statusTA, "Error", e.getMessage(), JOptionPane.ERROR_MESSAGE );
                   try {
                        e.printStackTrace( new PrintStream( "./log.txt" ) );
                   catch ( FileNotFoundException ee ) {
                        ee.printStackTrace();
         }The Server
    public class ServerHandler implements Runnable {
              private Socket s = null;
              public ServerHandler( Socket s ) {
                   this.s = s;
              public void run() {
                   try {
                        handlers.add( this );
                        DataInputStream dis = new DataInputStream( s.getInputStream() );
                        DataOutputStream dos = new DataOutputStream( s.getOutputStream() );
                        BufferedInputStream in = new BufferedInputStream( dis );
                        BufferedOutputStream out = null;
                        int count = dis.readInt();
                        for ( int i = 0; i < count; i++ ) {
                             File f = new File( Main.settings.SAVE_DIR );
                             if ( !f.isDirectory() )
                                  f.mkdir();
                             f = new File( Main.settings.SAVE_DIR + "\\" + dis.readUTF() );
                             out = new BufferedOutputStream( new FileOutputStream( f ) );
                             postStatusMsg( "Receving: " + f.getName() );
                             byte[] b = new byte[8192];
                             int read = -1;
                             while ( ( read = in.read( b ) ) >= 0 ) {
                                  out.write( b, 0, read );
                             postStatusMsg( "File Received" );
                             out.close();
                        in.close();
                        postStatusMsg( "Closing Connection" );
                        s.close();
                        postStatusMsg( "Connection Closed" );
                        handlers.remove( this );
                   catch ( IOException e ) {
                        Main.ShowMsgBox( statusTA, "Error", e.getMessage(), JOptionPane.ERROR_MESSAGE );
                        try {
                             e.printStackTrace( new PrintStream( "./log.txt" ) );
                        catch ( FileNotFoundException ee ) {
                             ee.printStackTrace();
         }

    Something like this, modulo bugs:
    // sender
    dos.writeLong(file.length());
    // send the file
    // receiver
    long length = dos.readLong();
    long current = 0;
    int count;
    while (current < length && (count = in.read(buffer, 0, (int)Math.min(buffer.length, length-current))) > 0)
      out.write(buffer, 0, count);
      current += count;
    }

  • Combining multiple files into a single PDF/A

    The issue brought up in another discussion is the loss of PDF/A conformity when “merging” multiple PDF/A files into a single file (I use PDF/A for preservation of corporate records). The “insert” option retains conformity but does not allow inserting multiple files in a certain order, unless you insert them one by one (which is a pain when you have 50 files to attach).
    The solutions I’ve come up with so far:
    1)     1)  In AAPro – combine files into a single PDF and then convert it to PDF/A using Preflight. This is easy, my only problem is that I don’t have AAPro (and AAStandard doesn’t convert to PDF/A).
    2)     2)  In AAStandard – combine files into a single PDF and then “print” to PDF/A. The problem of this “re-frying” is that it only creates PDF/A-1b (not 1a), bookmarks and OCR of scanned pages are lost, and files become significantly larger.
    I wonder if anyone knows a more intelligent way around this problem, provided that I only have AAStandard. Thanks!

    Well, when the .pdf is in the final, deliverable form; I open it in Mac preview mode and the sidebar is always extended showing a 'table of contents' rather than having each document in the pdf file have a number designating a page name, it shows each individual filename the pdf is composed of. Not too sure about bookmark, though. Thanks for the reply!
    If you want, I can send the file to you.

  • Joining data in multiple files into a single file using BPM

    Hello All,
             Can someone kindly give me any documentation or step by step procedure to join data in multiple file and display it all in one single file, using BPM.
    Thanks in advance,
    XI_Novice

    hi,
    Check this blog also...
    /people/pooja.pandey/blog/2005/07/27/idocs-multiple-types-collection-in-bpm
    /people/narendra.jain/blog/2005/12/30/various-multi-mappings-and-optimizing-their-implementation-in-integration-processes-bpm-in-xi
    regards

  • Multiple connections on a single socket simultaneously

    Hey everybody,
    Can a single socket on a client establish connections with different ports on a server at the same time?? I am awaiting for your replies.
    Thanks,
    Mani.

    No.

  • [CRS2008] Scheduling a report to multiple file output in single schedule

    Hi,
    Is there any way in CRS2008 / Infoview to scheduling one report to multiple file output in one schedule?
    i thought maybe it can, but still not found the way.
    Says,
    I have one report say "Report by Branch.rpt", the parameter prompt is BranchCode.
    I want to generate the "Report by Branch.rpt" for every BranchCode in separate output generate file. Like, "Report by Branch.rpt" for BranchCode A, or "Report by Branch.rpt" for BranchCode B.
    So, if i run the schedule, it will generate several report based on the report parameter given.
    Hope, would find the way.
    Thanks in advance.
    Regards.
    Edited by: fritzwijaya on Sep 20, 2010 3:47 AM

    For anyone still looking, the job can be seen under the Job History option on the home screen, but not on the Job History option under the report in the catalog - i am assuming this is becasue somehow im not referencing the report correctly in the ScheduleReport request message.
    Also, the jobId returned is a parent jobId, which when used to poll the job status, always returns a 'Scheduled' status. Im now adding 1 to this ID to get the status of my job - this returns the correct status of 'Success'.
    Still hoping someone has an idea on the getDocumentData question...?
    Thanks.

  • WIFI dies when transferring big files over the network

    Hi, I have Dell Inspiron 1520 with ipw3945 driver, when I transfer big files over the network, my wifi dies, anybody knows what could it be? If you need additional information, feel free to ask...
    Thanks in advance

    I guess we shall see. I can't imagine we are the only 7 with these issues.  Mine is mainly just lag... and overall slowness.  I hope to work through this.  If it lasts much longer I will have to revert back all 3 of my lappies to FC which I really do not want to do.  But on the lappies i connect via wireless 90% of the time and need it to work. 
    By the way how are you guys configuring your wifi?  I am using the iwl drivers and wicd.
    Well I did some more testing and loaded up netcfg and still get the same results so that rules out that part.  I also did some packet captures and I am getting a bunch of tcp retransmissions followed by tcp segment lost followed by a reset which in turn kills my rdp session (remote desktop protocol). I also went back several versions of the uucode driver and still get the same reults so I guess it seems to be a kernel issue.  Back to FC I go.  Damn shame...
    Last edited by BKJ (2008-10-08 01:08:56)

  • Transferring large file over internet

    Hi,
    I am attempting to transfer a large file over the internet (around 8GB), and I'm not sure what the best way of doing it is.
    This file is currently located on my desktop at home, and want to get it onto my laptop here (not going to be home for another month or so, so going home to get it isn't really an option!)
    I'm suscribed to MobileMe, but the maximum upload file size for iDisk was 1GB. If there is a way around this, let me know! Another option I had was using back to my back and just copying the file over, but this will take quite a while (not a problem, as I'm expecting it to take a while however I do it!)
    Any other suggestions? So far, the best option I have is just simply copying it using Back to my Mac, but please chime in if anyone as any better ideas!
    Thanks!
    Steve

    split it up into pieces (segment) and upload it, then download and re-assemble.
    http://www.machackpc.com/macosx/how-to-split-and-concat-a-large-file-using-termi nal/
    http://www.hjsplit.org/java/
    http://www.noixdecroco.com/htm/appli.php
    http://help.bombich.com/kb/dmg-and-remote/dimages
    #CCC can create segmented Read-only disk images#

  • How do you run Multiple Files on a single screen?

    Greetings; Please only respond if you've ACTUALLY done this, no opinions requested.
    I'd like to run several /.mov/mp4 files simultaneously on a single screen to simulate a 360deg view.
    If I start 5 cameras filming simultaneously (front, back, left, right,  rover), I'd like to sync the files, then combine the video on a single screen in large crossed  thumbnails/2"X2" format.   For example; Top, Bottom, Left, Right, Center images...
    How can this be done in Premier...?...and then exported to a standard format...?
    Again; Please only respond if you have ACTUALLY done this; no opinions please...
    Thank YOU

    If I start 5 cameras filming simultaneously (front, back, left, right,   rover), I'd like to sync the files, then combine the video on a single  screen in large crossed
    When I did this type of shot before I had to do some tricky stuff....and the hardest part for me was keeping me from shooting the other cameras and those other camera operators, not to mention trying not to see all those reflections of cameras and everything in the car, especially when I flew over the roof on wire !  Eventually I got it done but I had to basiscally use space lights with skirts and diffusion and then tent the car off with silk ( this was in a large football field sized stage )...and then put little holes in the silk for the "lenses"...and then hire a lot of people to walk that silk around as the cameras all dollied on track with the movement of the silk...  took forever to get the shot but it was beautiful if you squinted.
    good luck !
    ps...I when I edited this just like you want to do, with a lot of simutaneous screens within the frame, it looked so 3 dimensional people actually lost their balance watching it !

  • Automator workflow to TAR multiple files in a single directory into multiple TAR archives, in succession?

    Good afternoon,
    I have set up an automator service that TAR's a folder into an archive for me and it works quite nicely. Idealy however, I would like to be able to highlight several folders, right click and have automator tar each folder into it's own TAR archive, but do it one by one.
    Example:
    FOLDER 01
    FOLDER 02
    FOLDER 03
    Highlight all - Right Click - "TAR Folder" - Automator takes over at this point and TARs each one into:
    FOLDER 01.tar (Once complete moves onto:)
    FOLDER 02.tar (Once complete moves onto:)
    FOLDER 03.tar (Finished)
    I'm not 100% sure so I guess it would be a good time to verify, is there a problem with having the system try to TAR multiple folders at one time? If it is not a problem then I guess this discussion itself is pointless and I can simple right click on each folder and select "TAR Folder" and just wait until they're all finished. I would think that it would be ideal for the system to do each one individually and not try to do them all at one time.
    Any help would be appreciated.
    Thank you!!

    I don't think I have the following totally fleshed out but you probably can extrapolate on it.   This is a service which you can right click a set of folders  and it will tar the files within those selected folders with then file names "name xxx.tar", where name is the tar'ed file/folder and xxx is a count within the folder.
    I think that is what you originally specified so I am a bit confused by your script with the bit about Archive.tar. 
    Anyway here the basic idea:
    I ran the script directly with a folder argument just to see it indeed tar's up all the stuff inside, one tar per item.

  • Opening multiple files with a single click?

    I have searched this topic here and online elsewhere, but haven't gotten an answer.
    I teach English, and I download multiple student documents to grade. I want to just open all of them and go through one at a time quickly... like a stack of papers on my desk.
    I swear to goodness that I used to be able to select a folder full o' files and bam... they would all open in whatever app they were intended to open in. However, now I'm having trouble with this.
    I have a series of items... some are .doc some are .docx and some are .txt
    When I select all of them, only one .docx opens (and it opens in Pages because I have trained it to do this.)
    If I select all the .txts they all open in textedit like they should. But I can't get the stupid MS Word docs to do the same. I am not sure whether to blame Apple yet.
    I have tried Open With... Word, Pages, etc. but only one document opens at a time. What am I missing? I just did a perm repair and software update... nothing new under the sun.
    Any ides? Please? Thanks!

    There are a few ways you can open them:
    1) Select all of the files and under the File menu select "Open"
    2) Select all of the files and use the shortcut for open, which is command-O
    3) Select all of the files and drag them to the dock icon of the app you want to open them with
    You need to do these actions with the files selected and not the folder that they are in. To quickly select all items in a folder, click one of them and hit command-A (shortcut for "select all")

  • Can I have multiple files on a single time capsule?

    On a time capsule, can partition different backups for different files, i.e. different computers.

    As Neil says, you can easily back up multiple Macs to the same Time Capsule, as long as it's large enough (see #1 in the Frequently Asked Questions *User Tip,* also at the top of the +Time Machine+ forum). Each Mac's backups will be in a separate sparse bundle.
    If, as in your other post, any of those other computers are PCs, or even Macs using some other backup app, it gets complicated and messy, because of the way Time Machine backups will use all the space available, and the fact that, as Neil says, you cannot partition the internal HD.
    Your best bet in that case would be to attach a USB hard drive to the Time Capsule; you can partition it if necessary. Back-up one or more Macs to the TC's internal HD or USB drive; and the PC(s) to one or more separate partitions on the USB drive.
    See the Using TIME MACHINE with a TIME CAPSULE *User Tip,* also at the top of this forum.
    As noted in #Q3 there, there is a rather cumbersome way to reserve space on the TC's internal HD for things like the PC backups by putting a +disk image+ on it, but connecting a USB drive will be much easier.

Maybe you are looking for