Sending files with Mulicast sockets

Hi,
I'm trying to write a multicast sender/receiver applications for windows.
The problem I'm having is that the receiver create bigger file than the source (double or bigger).
Chcking with debugger the sender does not send the file more than one time & file length is measured correctly.
What am I doing wrong? Is Java multicast reliable on windows?
Please see below my code and comment.
Thanks,
Alonex
/* Multicast sender */
import java.io.*;
import java.net.*;
public class Outcoming extends Thread
     int port;     //4446     
     String multicastServer="230.0.0.1";     
     MulticastSocket out;
     byte[] outBuffer;
     String username;
     String msg;
     DatagramPacket dp;
     InetAddress multicastserverIP;
     static boolean done = false;
     public Outcoming() throws IOException, UnknownHostException
          port=4446;
          username="kostas";
          out=new MulticastSocket(4446);
          out.setTimeToLive(10);
//          out.joinGroup(InetAddress.getByName(multicastServer));          
     }/////////////////////Outcoming     
     public void run()
          while (!done)
          try {
               multicastserverIP=InetAddress.getByName("230.0.0.1");
          catch (UnknownHostException e)     
               System.out.println("Cannot resolve ip address");
          try {
               System.out.println("ttl"+out.getTimeToLive());
               out.joinGroup(multicastserverIP);
          catch (IOException e)
               System.out.println("Failed to join group");
          boolean readMore=true;
          String line="";     
          createAndSendPacket(line);
          while (readMore)
               System.out.print(">"); 
               BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
               try     {
                    line=br.readLine().trim();
               catch (IOException e)     {
                    e.printStackTrace();
               if (line.equalsIgnoreCase("quit"))     
                    readMore=false;
               createAndSendPacket(line);
//     }/////////////////////run
//     Returns the contents of the file in a byte array.
      public static byte[] getBytesFromFile(File file) throws IOException {
           InputStream is = new FileInputStream(file);
           // Get the size of the file
           long length = file.length();
           // You cannot create an array using a long type.
           // It needs to be an int type.
           // Before converting to an int type, check
           // to ensure that file is not larger than Integer.MAX_VALUE.
           if (length > Integer.MAX_VALUE) {
                // File is too large
           // Create the byte array to hold the data
           byte[] bytes = new byte[(int)length];
           // Read in the bytes
           int offset = 0;
           int numRead = 0;
           while (offset < bytes.length
                    && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
                offset += numRead;
           // Ensure all the bytes have been read in
           if (offset < bytes.length) {
                throw new IOException("Could not completely read file "+file.getName());
           // Close the input stream and return bytes
           is.close();
           return bytes;
     private void createAndSendPacket(String msg)
          int i,j=0,s=1;
         byte[] buf1=new byte[64000];
          try     {
               msg=username+"#!#"+msg;
//               byte[] buf=msg.getBytes();
               File fileTest = new File("c:\\test.exe");
               byte[] buf=getBytesFromFile(fileTest);
               int size = 64000;
               while (j<buf.length)
                    if ((s*64000)>buf.length)
                         size = buf.length-((s-1)*64000);
                         buf1 = new byte[size];
                         done=true;
               for (i=0;i<size;i++,j++) //buf.length;i++)
                    if (j==1822845)
                         System.out.println("here");
                    buf1=buf[j];
               if (i==size)
                    dp=new DatagramPacket(buf1, buf1.length,multicastserverIP , port);
                    out.send(dp);
                    try
                    Thread.sleep(3000);
                    catch (InterruptedException ie){}
                    System.err.println("Packet sent");
                    s++;
          catch (UnknownHostException e)
               System.out.println("createAndSendPacket: UnknownHostException");
          catch (IOException e)
               System.out.println("createAndSendPacket: IOException "+e.toString());
     }/////////////////////createAndSendPacket
     public static void main(String[] args) throws IOException, UnknownHostException
          new Outcoming().run();
/* Multicast Receiver */
import java.io.*;
import java.net.*;
public class Incoming extends Thread
     int port;     //4446     
     String multicastServer="230.0.0.1";
     MulticastSocket in;
     byte[] inBuffer;
     String username;
     String msg;
     InetAddress multicastserverIP;
     public Incoming()
          port=4446;
          msg="";
          try {
               in=new MulticastSocket(port);
               in.setTimeToLive(10);
          catch (IOException e)
               System.out.println("Failed to create multicast socket");
     public void run()
          try {
               multicastserverIP=InetAddress.getByName(multicastServer);
          catch (UnknownHostException e)     
          try {
               in.joinGroup(multicastserverIP);
          catch (IOException e)
               System.out.println("Failed to join group");
          while (!msg.trim().equalsIgnoreCase("quit"))
               readSocket();
               writeFromBuffer();
     private void readSocket()
          inBuffer=new byte[64000];
          DatagramPacket rcv=new DatagramPacket(inBuffer, inBuffer.length, multicastserverIP , port);
          try     {
               in.receive(rcv);
          catch(IOException e)
               System.err.println("Failed to receive incoming message");
     private void writeFromBuffer()
          try
          FileOutputStream fos = new FileOutputStream(new File("c:\\temp.exe"),true);
          fos.write(inBuffer);
          fos.close();
          catch(IOException ie){};
     public static void main(String[] args) throws IOException, UnknownHostException
          new Incoming().run();

(a) Multicast isn't reliable on any platform. Datagrams may be lost, duplicated, or delivered out of order, and datagrams greater than 534 bytes are unlikely to get though routers at all even if multicasts do.
(b) Why are you joining the multicast group every time around the loop?
(c) You are ignoring the actual length of the received datagram, just assuming it is 64000.
(d) In fact you are also ignoring exceptions when reading and still writing out 64000 bytes even if nothing was read at all.
All in all you need to rethink this.

Similar Messages

  • How to send file with original name through Mail adapter

    I have to send file with original name as attachment through Mail Adapter. I am picking the file from FTP server through File Adapter. I am not using message mapping because files do not have any standard format.

    Hi,
    Have you solve your problem ?...
    I have exactly the same scenario : pik up a file (file adapter) and send it in attachment by mail adapter without mapping (no IR)...
    I activated Adapter specific paramters properties in the File adapter sender and i can see the FileName tag in DynamicConfiguration section of SoapHeader in SXMB_MONI...
    I want to use MessageTransformationBean... BUT, how can i 'access' to FileName tag ???...
    Thanks...
    I setup modules like this :
    AF_Modules/DynamicConfigurationBean 1
    AF_Modules/MessageTransformBean rename
    sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean mail
    1 key.0 write http://sap.com/xi/XI/System/File FileName
    1 value.0 message.FileName
    rename Transform.ContentDisposition attachment;filename=message.FileName
    rename Transform.ContentDescription message.FileName
    rename Transform.ContentType application/csv-tab-delimited-table;name=message.FileName
    But my file name attachment is message.FileName....
    Edited by: Emmanuel JORAND on Sep 29, 2008 9:23 PM
    Edited by: Emmanuel JORAND on Sep 29, 2008 10:25 PM

  • System error when send file with Sender File Adapter

    Hi all,
    I have configured a "File To ABAP Proxy" scenario. After configuring, i executed a "Test Configuration" in Integration Directory and it's all OK. But this file unable to reach into ABAP Proxy Target. In the Runtime WorkBench\Message Monitoring,  I get an error message in below:
    Engine: Adapter Engine     
    Status: *System Error     *
    Start: 15.08.2008 14:04:01     
    End: 15.08.2008 14:19:01           
    Sender Service: BS_XI_SERVER     
    Interface Servic: urn://FILE_TO_PROXY
    MI_EMPLOYEE_OB
    In this case, I don't know why my Sender File Adapter is error and why status is "System Error" and why it can't reach into Target System. Can it concern a role user?
    ( For more clearly: I configured the source file and the path correctly. And i used the xml file with the content and the document name correctly. In general, the Sender Adapter File don't convert the sender file and its content is same as the Payload in the "Test Configuration", i think it is all OK.)
    Could anyone please help me to resolve this problem, anyone can explain this error, how can i resolve this error?
    Thanks a lot in advance,
    Vinh Vo

    Hi Chirag,
    1.I source structure is very simple as below:
    <ns0:MT_MATERIAL xmlns:ns0="urn://FILE_TO_PROXY">
       <MATERIAL>
          <WERKS>1000</WERKS>
          <MATNR>MAT00001</MATNR>
          <MAKTX>Chemical Material</MAKTX>
       </MATERIAL>
    </ns0:MT_MATERIAL>
    2. the Communication Channel Monitoring in Runtim WorkBench\Adapter Engine is OK for my Sender File Communication Channel, it's in Blue Light.
    However, i don't know what's FCC?
    Thanks and best regards,
    Vinh Vo

  • Send file with TCP/IP

    I would like to transfer a complete file with TCP/IP form a client to a server. I have a working example of using the TCP protocol to transmit data (as a string). I attached this Client-VI to this posting. The server program does nothing more than send the received data back to the client. Is it possible to send complete files with TCP/IP instead of sending strings? If so, would you be so kind and change my VI into a new one and send it back to me?
    If somebody has another idea to solve this problem, feel free to contact me!
    I use LabVIEW 7.0Express and WindowsXP.
    Thnaks, Dennis
    Attachments:
    ipc@chip_1.vi ‏38 KB

    Hi,
    I have a set of Vis that do the job. It's a LV5 Vi and I haven't translated it yet to LV7. It's two SubVis and two Vis that show you how to run the SubVis. The client asks a file that is in the server and the server sends it back. I'm attaching the two libraries llb, the client library and the server library. Please contact me if you have questions.
    Marce
    Attachments:
    TestTCPServerGetFile.llb ‏205 KB

  • Is there a contextual menu plug-in to send files with Mail?

    Anyone have any ideas if there exists a contextual menu plug-in that works between the Finder and Apple Mail which would allow you to email a file with a simple right-click.
    Unfortunately to make a comparison with a PC, in the same way that you can select +Send To+ > +Mail Receipient+ via the contextual menu.

    You can also make one yourself with Automator.
    With Automator (/Applications/Automator):
    Select "Files & Folders" and set 'Get content from' to "Use files and folders selected in the Finder when workflow runs"
    From the far-left panel, under Library, select "Mail".
    Drag "New Mail Message" and drop it under "Get Selected Finder Items" shown on the far right panel
    Select "Save as Plug-in" from the File menu. Give it a meaningful name.. "Send with Mail" should be OK. The plug-in type you want is "Finder"
    The action is now available from the contextual menu: More -> Automator -> Send with Mail
    Have a nice day

  • How to block send file with skype on windows store...

     Hi all,
     In domain environment, we can prevent users send file through skype by GPO with adm.
     (Link: http://community.skype.com/t5/Windows-archive/Blocking-file-transfer/td-p/1758460)
     But with skype on windows store (Like: Windows 8 ), this way isn't useful.
     So Is there anyway to we block send file on skype windows store?
     Thanks.

    Sorry, that isn't a Firefox support issue. Try AOL support for help with that.

  • Can't send files with OS X 10.9 Messages.app

    Hi,
    I upgraded from Lion to ML, and I was using Messages BETA in Lion before the update. Back in 10.7, I was able to send files (pictures mostly) with Messages to any other iMessage available contact.
    After the update to Mountain Lion, I can't send files any more, and have a lot of log entries about it:
    20-08-12 21:49:21,447 Messages[252]: [Warning] -[ChatTranscriptViewController _increaseResourceLoadCountForURL:] url called for url: ichat-resource://coreui/exclamation-pressed with nil _loadingIdentifiers
    20-08-12 21:49:23,337 com.apple.imfoundation.IMRemoteURLConnectionAgent[293]: [Warning] Denying xpc connection, task does not have entitlement: com.apple.private.imcore.imremoteurlconnection  (IMTransferAgent:292)
    20-08-12 21:49:23,337 com.apple.imfoundation.IMRemoteURLConnectionAgent[293]: [Warning] Denying xpc connection, task does not have entitlement: com.apple.private.imcore.imremoteurlconnection  (IMTransferAgent:292)
    20-08-12 21:49:23,338 com.apple.imfoundation.IMRemoteURLConnectionAgent[293]: [Warning] Denying xpc connection, task does not have entitlement: com.apple.private.imcore.imremoteurlconnection  (IMTransferAgent:292)
    20-08-12 21:49:23,339 com.apple.imfoundation.IMRemoteURLConnectionAgent[293]: [Warning] Denying xpc connection, task does not have entitlement: com.apple.private.imcore.imremoteurlconnection  (IMTransferAgent:292)
    20-08-12 21:49:23,339 com.apple.imtransferservices.IMTransferAgent[292]: [Warning] Remote loader crashed for request: <NSMutableURLRequest http://init.ess.apple.com/WebObjects/VCInit.woa/wa/getBag?ix=1>
    20-08-12 21:49:23,340 com.apple.imtransferservices.IMTransferAgent[292]: [Warning] Bag loading failed! Error (__kIMRemoteURLConnectionErrorDomain:-1): No se ha podido completar la operación (error __kIMRemoteURLConnectionErrorDomain -1). (null)
    20-08-12 21:49:23,341 com.apple.imtransferservices.IMTransferAgent[292]: [Warning] Remote loader crashed for request: <NSMutableURLRequest http://init-p01md.apple.com/bag>
    20-08-12 21:49:23,341 com.apple.imtransferservices.IMTransferAgent[292]: [Warning] Bag loading failed! Error (__kIMRemoteURLConnectionErrorDomain:-1): No se ha podido completar la operación (error __kIMRemoteURLConnectionErrorDomain -1). (null)
    The file transfer window in Messages shows "0 of XX KB sent" for all the files that I send, but at least I can recieve files from other iMessages available contacts.
    I also followed this hint without any luck so far: https://discussions.apple.com/message/19224592#19224592
    Does anyone knows how to solve this?
    Regards,

    Hi,
    Open Activity Monitor  and see if that IMTransferAgent is listed as running (it should launch and quit so fast that you can't read it)
    If it is listed then use Activity Monitor to Quit it.
    10:50 PM      Thursday; November 1, 2012
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Mountain Lion 10.8.2)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Sending files with 4.3.0.37 is "duplicating" trans...

    Hello everyone.
    I've been using Skype on Linux ( Ubuntu currently ) for some time now, and never ran into this issue previously.
    I couldn't get more than two attachments to go through, so I had to upload the images online.
    When sending any file via Skype. The file transfer initially shows a dialog as I expect with the single file ( s30.postimg.org/w17yx5vdt/skype_issue_step_1_of_3.​png ). Then, once the user accepts the transfer ( doesn't matter their Skype version ), a "duplicate" entry shows up (
    s30.postimg.org/vpqikeext/skype_issue_step_2_of_3.​png ) . The transfer then completes as it normally would but when it's complete, I'm still left with the duplicate ( s30.postimg.org/wtamwczkx/skype_issue_step_3_of_3.​png ) .
    Besides the obvious issue, this has grown to become a pain, as I send several files throughout the day, and I can't auto-clear them out with this issue.
    Does anyone know of a workaround for this, or is there a way I can submit a more formal bug submission somewhere?

    Yes, sorry for not being more clear in my original post. This happens now on the latest Skype for Linux ( 4.3.0.37 ) regardless of the recipient, for which I've confirmed none of them are running second instances ( as SørenHolm has confirmed ).
    To clarify, I've confirmed with every contact I've sent files to that they are only running a single instance, but yet for every client I send files to with the new client, I'm experiencing the issues outlined in my first message.

  • I cannot send files with Adobe Send as no button on screen

    There is no "send" button on my screen when trying to send files by Adobe Send. I had no problems with SendNow and am a subscriber. How do I get it to work?

    PeterHelp
    Files
    Send
    Fill & Sign
    Export PDF
    Create PDF
    Combine Files
    Organise Pages
    Acrobat
    Selected Files+ Add Files
    80004721.tif
    80004751.tif
    80004871.tif
    80004901.tif
    80004971.tif
    80004991.tif
    Recipient Page
      Add Your Logo & Colour  (Edit) <>
      Create Anonymous Link  (with basic usage information)
      Send Personalised Invitations  (with detailed tracking)
    Send To
    [email protected]
    Subject & Message
    Cancel
    [email protected]
    Peter Marsh Photography
    11 Duck Lane
    Laverstock
    Salisbury
    SP1 1RS
    UK
    Tel:     01722 337903
    Mob:  07831 484604
    Email: [email protected]

  • Cant send file with outlook in preview

    Hello,
    I'm a new Mac user and must say very happy with my change.
    However I have one problem I can't seem to solve.
    My work forces me to use Microsoft Outlook on my Mac.
    But I can't seem to figure out how to send files from the preview program.
    When selecting "send e-mail" in preview. It always opens the Mail program, even though I set Outlook as the standard mailing program.
    Anyone has an idea on how to fix this?
    Thank You!

    Hi Sig,
    I also used your advice to add outlook to convert to pdf...Thanks
    I now sit with the problem that when I click on the Outlook tab, it opens up the window in the background of my desktop, and I have to "minimise panels" in order to get to it? Any advice, on how to just get the window to pop up when clicking on Outlook PDF?
    Hpe this makes sense?
    Cheers
    N

  • Sender File with FCC coming with empty file

    Hi Experts,
    Scenario: File(FCC) to Proxy
    Error: CSV file picking up from source directory but its showing empty in sender CC (Actual file contains data in source directory) and find below attached Conversion parameters. Please let me know if any changes in the configuration.
    Document Name: MT_Legacy
    Document Name space: http://retails.com/pi/LEGACY/Purchasing/TECHNICAL_DATA
    Recordset structure: Header,,Items,
    Recordset sequence: Ascending
    Keyfiled names: NumFacture,Constant
    ignoreRecordsetName----
    true
    Header.fieldNames----
    a,s,d,f,g,e
    Header.keyFieldInStructure----
    ignore
    Header.keyFieldValue----
    05
    Header.endSeparator----
    nl
    Header.fieldSeparator----
    Similar to Items also
    Query: is this error related to source file (unexpected format) or Sender File CC configuration.
    Regards,
    FHM

    Hi HK,
    I see that there are two keyfield names in your content conversion. Are they for different nodes?
    " Keyfiled names: NumFacture,Constant "
    Yes...those are coming from two different nodes like one from Header and another one from Items.
    And also the you have provided key field value as 05 and what about the other key field?
    Another key field value have given 43
    one more thing Key filed value must be always constant right?
    Thanks,

  • Send File with Bluetooth

    I am attempting to send/beam a file to another friend using Bluetooth and my Bluetooth is enabled, but when I click the "Send File" tab under my Bluetooth icon nothing happens.
    Suggestions?

    for what it is worth, i have never been able to get the dropdown menus from the bluetooth icon to function in Tiger, UNLESS i open and keep open in the background 'Bluetooth File Exchange' located in the utilities folder. the behaviour is odd and i am surprised no one else has noticed this 'bug'.

  • Sending file with bluetooth from laptop to phone

    I am having great difficulty sending file from laptop to phone using bluetooth. I can send files from phone to laptop.
    I have followed the instructions from this link: http://wiki.archlinux.org/index.php/Bluetooth .
    also i am using xfce4 as my Desktop Environment.
    any other help would be greatly appreciated.

    The thing is, this is not the topic you started, so it is solved . The OP used Xfce, and I linked him to a solution on how to do so - on Xfce. So yes, it is solved. He's the only one to say so. As you say, your problem is different, so you might want to bump your own topic instead .

  • Sending files with and without BPM in one Interface.

    Hi All,
    I have to send three files to my receiver system. 2 files of same structure after little mapping need to be merged into single file (Using BPM) and once this is successful the third file needs to be posted without any mapping.
    I have thought of
    1. using two communication channels activated using a UNIX script externally
    2. using two comm channels with a activation time difference, i.e the 3rd file should be polled after some time when the first two files polled, but this is not helpful as if the two files doesnt process properly then 3rd file is not desired.
    Now my question is can we do this scenario using 1 comm. channel with EOIO , masking or anyother option.
    <b>Note: the third file should always be send after the processing of the first two files completes successfully.</b>
    Thanks & Regards.

    1. put two file in source folder and make synch scenario using BPM ,
    2. put third file in some other folder than source folder.
    3. after getting successful synch file responce, in the synch receiver file channel run OS command to put third file from other folder to source folder.
    hows that ???

  • How to send File with Same name to Receiver

    HI Frnds,
    In my peoject i have one scenario,
    I have to access Orders is the name of file , available in FTP Server, i have to send same file to Receiver side with same name Orders
    Is it possible with same name dynamically??
    Regards,
    Raj

    hi,
    You have to go for variable substitution option available in receiver file adapter,but for that you have to get the file name in receiver payload.
    http://help.sap.com/saphelp_NW04/helpdata/en/e3/94007075cae04f930cc4c034e411e1/frameset.htm
    these links are  also helpful
    /people/jayakrishnan.nair/blog/2005/06/20/dynamic-file-name-using-xi-30-sp12-part--i
    /people/jayakrishnan.nair/blog/2005/06/28/dynamic-file-namexslt-mapping-with-java-enhancement-using-xi-30-sp12-part-ii
    /people/sriram.vasudevan3/blog/2005/11/21/effective-xsl-for-multimapping-getting-source-filenames-in-legacy-legacy-scenarios
    regards,
    ujjwal kumar

Maybe you are looking for

  • How do I hide the app names on the Dock?

    I want to turn off the app names that display on the Dock. If it doesn't exist, I think it should be done. We (most people, I guess) already know most of the apps on their Dock. So hiding it will help making the interface more sleek.

  • Converting microsoft sql server documents into portal items

    Our customer currently has a number of documents stored in a Microsoft SQL server database as an 'image' datatype. They would like to programatically move all these documents from the sql server into the portal database and store them as portal items

  • Freehand MX line weight issue?

    I am having a problem seeing the difference between say a 1pt line and a .5 line when viewing and creating an illustration at 100%. The line weights look identical. If I view or edit the illustration at say 200% the line weight difference is noticabl

  • Setting up the server Mac OS 10.8.3 on a dynamic IP and running Podcast Producer

    Greetings! I need to configure MAC OS X Server 10.8.3 with the version of software to work with a dynamic IP via dyn.com / dns / or what is a better way. And we must port the Podcast Producer to version 10.8 the fact that it supports both free softwa

  • Cannot get past the new T's & C's to download apps

    Hi People, I'm struggling to download any apps all of a sudden. ..... It is telling me that I have to agree to the new T's & C's, which I do, then it times out almost immediately so I cannot get any further. ... This only happened since I upgraded to