Sending multiple files using one socket

Hi guys
I'm working on a simple app that sends multiple files over LAN or I-NET. The problem is that the app run seems to be non-deterministic. I keep getting this error on the client side:
java.io.UTFDataFormatException: malformed input around byte 5
        at java.io.DataInputStream.readUTF(Unknown Source)
        at java.io.DataInputStream.readUTF(Unknown Source)
        at service.DownloadManager.storeRawStream(DownloadManager.java:116)
        at service.DownloadManager.downloadFiles(DownloadManager.java:47)
        at manager.NetworkTransferClient$1.run(NetworkTransferClient.java:104)The byte position changes every time I run a transfer. The error is caused by this line: String fileName = in.readUTF(); Here's the complete code:
Client
private void storeRawStream() {                               
        try {
            FileOutputStream fileOut;                       
            int fileCount = in.readInt();           
            for(int i=0; i<fileCount; i++) { 
                byte data[] = new byte[BUFFER];
                String fileName = in.readUTF();               
                fileOut = new FileOutputStream(new File(upload, fileName)); 
                long fileLength = in.readLong();                                 
                for(int j=0; j<fileLength / BUFFER; j++) {
                    int totalCount = 0;
                    while(totalCount < BUFFER) {                       
                        int count = in.read(data, totalCount, BUFFER - totalCount);
                        totalCount += count;                 
                    fileOut.write(data, 0, totalCount);
                    fileOut.flush();
                    bytesRecieved += totalCount;                                  
                // read the remaining bytes               
                int count = in.read(data, 0, (int) (fileLength % BUFFER));                                        
                fileOut.write(data, 0, count);              
                fileOut.flush();
                fileOut.close();      
                transferLog.append("File " + fileName + " recieved successfully.\n");  
        } catch (Exception ex) {
            ex.printStackTrace();
    }Server
public void sendFiles(File[] files) throws Exception {
        byte data[] = new byte[BUFFER];
        FileInputStream fileInput;                                       
        out.writeInt(files.length);              
        for (int i=0; i<files.length; i++) {   
            // send the file name
            out.writeUTF(files.getName());
// send the file length
out.writeLong(files[i].length());
fileInput = new FileInputStream(files[i]);
int count;
while((count = fileInput.read(data, 0, BUFFER)) != -1) {
out.write(data, 0, count);
bytesSent += count;
fileInput.close();
out.flush();
Does anybody know where's the problem? Thanx for any reply.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Send the length of each file ahead of each file, with DataOutputStream.writeLong().
When reading, read that long, then stop reading bytes when you've read exactly that length.

Similar Messages

  • Sending a File Using DataGram Sockets

    I writting one java program that can be used to transfer a file from one computer to another computer.
    I wrote using Sockets.
    But i want to do that using DatagramSockets. Can we send a file using DataGramSockets?
    Please reply soon.

    You can use DataGram but it is harder.
    One issue is you need to retransmit missing packets. This means you need to keep track of which packets have been sent and be able to send missing ones again.
    If Socket work for you why do you want to use DataGrams

  • Sending multiple files using file adapter

    The scenario I am implementing requires multiple files of different names to be picked up by my adapter. I dont want to create different file adapters for each file. I tried using the "Additonal Files" option in the sender file adapter in my configuration, but am not able to do the same. Any idea as to how the configuration for multiple files for same adapter isto be done?

    Hi bhavesh
    Fundamental of adapter configuration is you have to give valid xml structure to XI, so you will define your configuration according to your requirement.
    for .xml you have file as a message protocol while for .csv you have file content conversion as a message protocol.
    So you have to define adpater configuration for sender side for one type of structure.
    So you need a different communication channel for different extentions.
    for diffrent strcutures,having same extention, you can execute this.
    Please make me clear that what is your scenario?
    why you need to pick all files under a directory with a same communication channel?
    Regards
    Piyush

  • How to send a file using IOCP?

    When using blocking sockets, all I had to do to send a file was to open the file and loop through it and send it in chunks.
    But I find sending a file using overlapped sockets to be more challenging. I can think of the following approach to do it:
    I open the file and send the first chunk, and I keep track of the file handle and file position.
    Now when I get a completion packet indicating that some data has been sent, I check to see if the socket is currently in the process of sending a file, and if it is, I retrieve the file handle and file position and send the next chunk.
    I repeat step 2 until I reach the last chunk in the file, and then I close the file.
    Is this approach correct?
    Note: I don't want to use TransmitFile().

    This approach is more or less correct, but maybe you'd have to know some more things.
    If send "returns" it means, that you buffer has been copied into the internal buffer of system or the network interface card or whatever... in general it means, that you can free/reuse the buffer you have used, but it doesn't mean, that the data
    has been delivered (it does not even mean it has been sent already).
    That's why I'm normally using some flow-control (messages from the receiver) to verify the real data flow.
    The next point is, that you shouldn't read from the file only after you got the ok that the first chunk has been sent. You should read the data as soon as possible so that you can respond much quicker to a send-complete-message. I'd recommend to send using
    multiple buffers.
    Rudolf

  • Send multiple files in different directories using Receiver File Adapter

    Hi Experts,
    I have one File to File without ESR scenario where I have to pick multiple files from different directories and to save them in different directories on receiver side.
    Can anyne help me to send multiple files in different directories using receiver file adapter.
    Is it possible??
    Any help will be appreciated.
    Regards,
    Danish

    hi ,
    that is possiable without esr,
    we need to create one sender communication channel , in that  we nend to use "adavnced selection for source file " for sending multiple files from multiple directories.
    we need to create 'n' receiver communication channels and 'n' receiver agreements based on communication channels .
    in receiver determination, provide multiple receivers
    In interface determination , provide * symbol for receiver communication components
    thanks,

  • I recently bought two iMac quad core i5 processor speed 2.5 Ghz. Every time I use Air Drop and I send a file from one iMac to the other, a black curtain drops and I am asked to restart the computer!!! What can I do?

    I recently bought two iMac quad core i5 processor speed 2.5 Ghz. Every time I use Air Drop and I send a file from one iMac to the other, a black curtain drops and I am asked to restart the computer!!! What can I do?

    That's a kernel panic and indicates some sort of problem either with the computer's hardware or software. Visit The XLab FAQs and read the FAQ on diagnosing kernel panics. It would help to post the panic log: Mac OS X- How to log a kernel panic.
    Meanwhile, try booting the computers into Safe Mode then restarting normally. If this is simply a disk repair or cache file problem then this may fix it.
    You can also try creating a new admin account on each computer then booting into the new account. This would help determine if the problem is related to a bad file in the user accounts.

  • How to send multiple files by using File Adapter

    Hi Experts,
    I am trying with the scenario by using the File Adapter.
    As per my requirement, I need to send multiple files (like FileA.xml, FileB.pdf, FileC.txt, FileD.html etc) to the Target system.
    I have seen ‘Additional Files’ option, in Sender Communication channel. But I am not sure how to give the parameters, in case if I would like to send the multiple files as mentioned above.
    Could someone please explain about the steps, that I need to proceed further?
    Thanks in advance.
    Sree

    Anand,
    Thank you for your reply.
    My requirement is to send the multiple files like inone.xml, intwo.txt etc. In the Sender Communication channel, I had provided ' inone.xml ' in the File Name field under the "File System Access Parameters" section.
    Next I had chosen "Additional Files" option as Checked and provided ' intwo.txt ' in the field name of "File List".
    After activation, i have provided those two files (inone.xml, intwo.txt) in the Source folder. It is not processing? What could be the problem ?
    Thanks
    Sree

  • Why can't i send multiple files through airdrop ? , it accepts but shows only one photo

    why can't i send multiple files through airdrop ? , it accepts but shows only one photo

        Hello there Laurengrayce,
    I message all of the time and I want you to do the same, to anyone you would like!  Demmo provided a good suggestion of having this person check their services and ensuring they're setup as a 10-digit number, but I would like to provide some of my own suggestions.
    If they are in fact already setup as a 10-digit number, I would recommend deleting this persons contact from your phone as well as the entire messaging thread (long press and hold on thread to delete).  Readd them to your contact list and try again.
    Please advise if this continues and they've already checked with their provider.
    Thanks,
    MelissaM_VZW
    Follow us on Twitter @vzwsupport

  • Send many files through a socket without closing Buffered Streams?

    Hi,
    I have an application that sends/receives files through a socket. To do this, on the receiver side I have a BufferedInputStream from the socket, and a BufferedOutputStream to the file on disk.
    On the sender side I have the same thing in reverse.
    As you know I can't close any stream, ever.. because that closes the underlying socket (this seems stupid..?)
    therefore, how can I tell the receiver that it has reached the end of a file?
    Can you show me any examples that send/receive more than one file without closing any streams/sockets?

    Hi,
    As you know I can't close any stream, ever.. because that closes the underlying socket (this seems stupid..?)Its not if you want to continuosly listen to the particular port.. like those of server, you need to use ServerSocket.
    for sending multiple files the sender(Socket) can request the file to server (ServerSocket). read the contents(file name) and then return the file over same connection, then close the connection.
    For next file you need to request again, put it in loop that will be better.
    A quick Google gives me this.
    Regards,
    Santosh.

  • Send multiple files in separate e-mails

    Hello!
    I want to send multiple files from finder in separate e-mails, but I can't find a way to do this in Mavericks and Apple mail (or gmail). In windows XP it was simple as Send to/Mail recipient. Is there an option similar to this is MacOSX?
    Thnx,
    Gas

    #Eric
    Of course that would work, but it is tiresome to do for every file (open-attach-write subject-insert recipients-send), and that is exactly what I would like to avoid.
    #Csound
    My Mail works fine, but I use gmail webmail usually. Now that I changed the preferences, so Mail is the default it works with the shortcut menu :-)
    But, when I select more files, it attaches them to one e-mail, and not per/file. Is it possible to split them to different mails so they can be sent individually?
    Thanks.

  • How can I convert multiple files at one time and not one at a time

    How can I convert multiple files at one time and not one at a time

    Hi Plissey1950,
    Sorry for the lengthy delay to a response.  Are you trying to convert multiple files to individual PDF files at the same time? (not combine them).  If so, you'll need to use Adobe Acrobat for this function. The CreatePDF service does not have the ability to convert multiple files to multiple individual PDF files.
    Thanks,
    David

  • How to attach multiple file in one mail

    Hi,
    I've problems with sending multiple files via Gmail account (Ipad version)  When sending the photo or video, I've to just click the photo and choose send to mail one by one. Any simpler way?  Sometimes i did sent both mpg and jpg but the reciepient didn't see any attachment too
    Anyone can help advise how to attach different file (doc, video, photo) in one mail will be a lot appreciated. Thank you so much

    You can attach multiple pictures to an email on an ipad2. Don't know about original iPad.
    Choose a photo or take a screen shot (hold down home button and button next to volume control at same time--screen shot now will appear in photos).
    Go to photos and edit your picture or screen shot, save it, then hold down on the image and copy it.
    Go to mail, create a new mail and paste it in.
    Save you mail as a draft.
    Go back to photos and select a different photo, copy it, and return to your draft, and paste it in. Repeat if you need to add more.
    Anything that you can take a screen shot or have an photo of can be pasted in one at a time into that draft email.
    If mail gets uncooperative, during this process, then double click on home button and quit multitasking mail, then open up mail again and send your draft. Uncooperative means gets frozen.

  • To Move Multiple Files from one directory to another.

    Hi,
    I need to move multiple files from one directory in UNIX (application server ) to another. I need something like an FM 'STRALAN_COPY_FILES' which is also valid in ECC 6.0.
    Thanks in advance.

    Hello Sachin
    Below you see a copy of how to use EPS_FTP_PUT using transaction SE37.
    Import parameters               Value             
    RFC_DESTINATION =                 NONE              
    LOCAL_FILE             =         filename          
    LOCAL_DIRECTORY   =              /dir1/dir2        
    REMOTE_FILE             =        filename          
    REMOTE_DIRECTORY   =             /dir1             
    OVERWRITE_MODE        =          F        " force -> overwrite existing file                 
    TEXT_MODE                    =   B               " binary
    TRANSMISSION_MONITOR            X       " display transmission monitor            
    *RECORDS_PER_TRANSFER            10                
    *REQUESTED_FILE_SIZE             0                 
    *MONITOR_TITLE                                     
    *MONITOR_TEXT1                                     
    *MONITOR_TEXT2                                     
    *PROGRESS_TEXT                                     
    *OBJECT_NAME  
    Regards,
      Uwe

  • Send A file Using JMS

    I want to send a file Using JMS.. and want to have
    These Details in the message that send.
    Receivers IP address & The file
    That mean I want to send a File from one client to another client Using a Queue
    Can Anyone help me to solve this problem
    thanks

    Read the file then use a JMS BytesMessage or TextMessage. Add your own JMS header for the recievers ip and any other info you want to annotate the message with.
    Watch out for character encoding and max file size problems.
    If your client / server are not on the same network you're likely to run into firewall issues.
    Don't kid yourself that this will be a transactional solution.
    Assumes both clients are Java (JMS headers are a pain to read otherwise)

  • Multiple selections to multiple layers or multiple files with one go ?

    Hi,
    how to convert multiple selections to multiple layers or multiple files with one go ?
    Thanks!

    You may want to ask over at
    http://forums.adobe.com/community/photoshop/photoshop_scripting?view=discussions
    or
    http://ps-scripts.com/bb/
    I think there are Scripts about for the task or at least ones that could be adapted without too much problems.
    The usual approach is, I think, creating a Work Path from a Selection and then using (expanded) Selections based on the individual subPathItems to intersect with the original selection.
    Of course there are possibilities for bad results …

Maybe you are looking for

  • Netsh does not work to set IP address of "Wireless Network Connection"

    On Windows 7 Professional This set of commands work for configuring the "Local Area Connection" netsh interface ip set address name="local area connection" static 74.94.87.157 255.255.255.248 74.94.87.158 1 netsh interface ip set dns name="local area

  • Error connecting to itunes

    My 2nd generation apple Tv for some reason no longer connects to itunes -- it on the network as Netflix, YouTube etc.. all work. I've logged out and back into iTunes multiple times... it says it's unable to connect to iTunes. What gives?

  • Changes in edited & saved template do not show up in page 2 or 3 of letter.

    I am new to Pages '09. I chose a template for a "Traditional Letter". It immediately picked up my name (from the computer registration, I think), as the header read "Geraldine's Laptop Dwyer". I edited that to read, "Geraldine Dwyer", added my phone

  • Some incoming messages are not received in outlook

    Using Iphone 4. Most of the time I receive messages from a POP account on the IPhone and on my Outlook2010 client. Once in a while I receive one or more on the IPhone and they never show up in Outlook. This is DNSExist Squirrel mail server. The messa

  • Mac will not boot from hard drive or install disc

    Hello All In dire need of advise...my intel Mac will not boot, even tried booting to the Snow Leopard install disc and all I'm getting is the white screen, apple logo and the wheel. Just before this happened there was a buzzing sound like the fan was