Datagram Socket  send different sizes Buffers ...

hi,
I'm sending different sizes Datagrams from a datagram socket
so how can I receive them
I've tried to send the packet in two packets the first one is fixed size that carries the size of the real data then create a suitable buffer on the client side to receive the second packet but the result is very slow ...
I'd like to know any suggestions about how to do this properly
to reach a stream like synchronization between the client and the server ..
thanks in advance

use a receive buffer large enough for the largest package possible on your network. Typically, this is 1500 data bytes, but it depends on the network technology. If you want to be sure, allocate a 65536 bytes buffer, which will fit for any technology. But typically, 1550 will fit in a LAN.

Similar Messages

  • Can u tell how to send the pictures using datagrams sockets in java

    hi to all, i am making chat application , i am datagrams socket(packets) for sending and receiving messages . datagrams only send and receive messages in bytes . can u tell me how to send the picture to other person using datagrams.
    Thankyou.

    look her
    http://forum.java.sun.com/thread.jsp?forum=31&thread=330989&tstart=0&trange=15
    and look up Serialisation

  • Help: Send and Receive through Datagram Socket

    I am trying to create a client/server using Datagram Socket (UDP) as communication. I have a Recive and a Send class that implements runnable and are responsible for receiving and sending of message. I have two other classes Server and Client that are utilizing these. Now i can get the receive and send to work fine, but i am having trouble retrieving the message from the receive thread that i created in each of server/client. I've tried inserting a method so the server/client can call on to get the message (Receive.Get_Message()) but unfortunately this isn't working as i wanted. Since my server and clients are not implemented as runnables, i can only issue the command in some serialize fashion. What i really want to do is that whenever the message is receive by the Receive thread, it will immediately be send back to server/client and display right then, independent of what i was doing. (i have a command interface for S/C so it just sits there to wait for command, now what i would like is to have the S/C display the message it gets immediately after it gets it even when it's waiting for user input. since my program is waiting for a command, i really could not use the method describe above to achieve this) Could anyone help me with this?
    Thanks!
    Hung-Hsun Su

    u cant use the observer pattern. or at least i can't figure out how to implement it with sockets.
    you should use threading.
    public void run()
      while(true)
         //keep reading from socket
         InStream output = socket.getInputStream();
         InputStreamReader ir = new InputStreamReader(output)
         BufferedReader reader = new BufferedReader(ir);
         String s = null;
         while(s == null)
           s = reader.readLine();
         //then do whatever you want to the received string "s"
    }

  • Datagram Packets sending too fast?

    I am testing sending UDP packets as fast as possible over a 10/100 switch. It seems my problem is actually sending to fast because when I insert a wait (1ms works) into the send routine all the packets are received. When I do not wait I seem to lose about 1%-5% of 20,000 1kB packets (during testing). It seems hard for me to believe the receive routine is doing too much work to cause packet loss because all it is doing is adding the packet to a Queue (which is really a LinkedList). Any comments on this would be very helpful. Some of my code is below:
    The send routine:
    public void sendAll()
    // While still packets in send Queue
    while(!sendQueue.empty())
    // A 1ms wait here works
    send((DatagramPacket)sendQueue.dequeue());
    The receive routine (in the run method of a Thread):
    // Create a datagram socket, bound to the specific port 2000
    DatagramSocket socket = new DatagramSocket(2000);
    boolean f = false;
    while(!f)
    // Create a datagram packet, containing a maximum buffer of 1048 bytes
         DatagramPacket packet = new DatagramPacket( new byte[1048], 1048 );
    // Receive a packet - remember by default this is a blocking operation
    socket.receive(packet);
    // Add the received packet to the receive Queue
    // This routine also checks the first byte of the packet's data to determine packet type
    addToReceiveQueue(packet);
    P.S. The program now does not do anything about packet loss, I will be adding some flow contol soon. If anyone knows some good links to implementation concerning sliding window/flow control for UDP a link would be great. And oh ya, I am required to use UDP - no TCP for me :)

    use setReceiveBufferSize to sets the SO_RCVBUF option to the specified value for the DatagramSocket. The SO_RCVBUF option is used by the the network implementation as a hint to size the underlying network I/O buffers.
    Increasing SO_RCVBUF may allow the network implementation to buffer multiple packets when packets arrive faster than are being received using #receive().

  • Datagram socket and security manager

    I have subclassed the security manager to implement my own network security rules.
    However when the receive(datagramPacket) method is called by the my datagram socket, the host parameter passed to the checkAccept(host, port) method does not belong to the sender of the packet(to be received).
    How then can malicious addresses be blocked by the security manager, as suggested by the comments in the source code of DatagramSocket.
    Any help is greatly appreciated. Thank you in advance.

    However when the receive(datagramPacket) method is
    called by the my datagram socket, the host parameter
    passed to the checkAccept(host, port) method does
    not belong to the sender of the packet(to be
    received).It should. What are you getting instead?

  • Datagram socket is not working

    Hi,
    I made a datagram socket and try to send a byte array. but when I called socket.send method it returned an error that an operation is attempted on invalid socket. What I am missing
    here is my code...
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="480" height="262">
    <mx:Script><![CDATA[
    private var udp:DatagramSocket = new DatagramSocket();
    private var address:String = "255.255.255.255";
    private var port:uint = 200;
    private function OnSend():void
      udp.addEventListener(DatagramSocketDataEvent.DATA, RecvUdpDataHandler);
      var byteArray:ByteArray = new ByteArray();
      byteArray.endian = Endian.LITTLE_ENDIAN;
      byteArray.writeMultiByte("dvcrNetshare", "US-ASCII");
      byteArray.writeUnsignedInt(123);
      udp.send(byteArray, 0, byteArray.length, address, port);
      udp.receive();
    private function RecvUdpDataHandler(obj:DatagramSocketDataEvent):void
      var str:String = obj.srcAddress;
      var srcport:int = obj.srcPort;
    ]]></mx:Script>
    <mx:Button x="206" y="134" label="Send" click="OnSend()"/>
    </mx:WindowedApplication>
    Thanks

    You can call Apple and appeal their decision if you wish to (or go back to the store and ask for a supervisor or manager to assess your device - basically dispute the genius claim and ask to have it bumped up the chain of command).  Ultimately though they are the ones who decide if your damage is a warranty-related defect or something caused by accidenatal damage or abuse.  If they say you are not eligible for a warranty repair, then you pay the fee for an out of warranty repair.

  • Datagram Sockets

    Hi Folks. I am curently devising an presence service andinstant messaging system on UNIX. The problem is I am looking to open a datagram socket connection with a client on another computer on port 1115. Hhow am I able to send them a message without them having to run any program on their system. How can I just send the message to them, like a proper instant messaging system.
    PS How do i get them to listen on port 1115, without them having to do anything. How can I open a server connection on port 1115 for them
    Any help is appreciated
    Ewan

    When you "proper instant messaging system" I assume you mean something like talk or ytalk rather than ICQ or YahooIM. The former have daemons that run listening for messages which are started by the system.
    the user (or administrator) of the machine is going to have to explicitly open a socket to listen for connections on the port, by running a program or by having a daemon start at boot.

  • Datagram Socket Problem !!!!!!!!!!!!!!!

    Hi to All ,
    I am facing problem regarding the Datagram Socket Programming .
    I wana to make a java program that is using the datagram socket. I wana to retrive the IP Address of all the machines that are connected in a local network by using the datagram Socket !!!!!!!!!!!!!!
    As i am new in java Socket Programming , Can any body help me How am i sends a Broadcast Packet to all the machines that are connected in a local network , so that i retrieve the IP Address of all the machines that are presented in a local network
    Please give the Solution

    You can't use any Java to find all the machines on your network (whatever that means). You will need to shell out and parse the output from the shell.
    If you want to simply use datagram sockets to send UDP broadcasts, the Javadoc covers it in some detail.
    However, UDP is called a "send and pray" protocol - you send the message and pray that the client receives it. Also, there is no acknowledgement from the client when the message is received. So, in a nutshell, you cannot use multicasts to find clients.
    You need to use some other protocols in the TCP/IP stack for finding machines on the network - and Java does not have any pre-built support for these.

  • Urgent Datagram Socket

    hi to All,
    I am facing some problem when i am broadcasting a data packet by using the datagram socket in java
    I am using the IP Address 255.255.255.255 to broadcast a packet . The Packet is send , but the programs goes in Indefinite till when receiving a Message from the Machines that are connected in the Local Network !!!!!!!!!!!
    Actually , i wana to collect all the Machines IP Address by sending a Broadcast Packet(by using UDP) . Can i body tell whts the Solution of this probelm , so that i retrieve the IP Address of the Machines that are connected in a local Network

    " You can only do it if you know that all machines will respond to an udp package on some port."
    HI
    I am having trouble in broadcasting the data on 255.255.255.255 at port 3988.
    Can you people send me the code for -
    How to broadcast the data on 255.255.255.255 at port 3988 ??
    and
    How it can be received by any client machine at its port 3988 and How client can come to know from where the data is coming i.e. from which machine the data is coming.
    As you have told that it is possible if we know the port "You can only do it if you know that all machines will respond to an udp package on some port.", the port is 3988.
    Thanks & Regards
    Abhishek

  • How to send different type of data

    Hello, everyone,
    I am trying to send different types of data between client and server.
    For example, from server to client, I need to send some String data, using PrintWriter.println(String n); and send some other stuff using OutputStream.write(byte[] b, int x, int y). What I did is setting up a socket, then send them one by one. But it didn't work.
    I am just wondering if there is anything I need to do right after I finished sending the String data and before I start sending other stuff using OutputStream. (Because if I only send one of them, then it works; but when I send them together, then the error always happened to the second one no matter I use PrintWriter first or the OutputStream first)

    To send mixed type of data by hand allways using the same output/input stream, you could do:
    on server side
            ServerSocket serverSocket = null;
            Socket clientSocket = null;
            OutputStream out = null;
            try
                /*setup a socket*/
                serverSocket = new ServerSocket(4444);
                clientSocket = clientSocket = serverSocket.accept();
                out = new BufferedOutputStream(clientSocket.getOutputStream());
                /*send a byte*/
                int send1 = 3;
                out.write(send1);
                /*send a string with a line termination*/
                String send2 = "a string sample";
                out.write(send2.getBytes("ISO-8859-1"));
                out.write('\n');
            finally
                try { out.close(); }
                catch (Exception e) {}
                try { clientSocket.close(); }
                catch (Exception e) {}
                try { serverSocket.close(); }
                catch (Exception e) {}
    on client side
            Socket clientSocket = null;
            InputStream in = null;
            try
                clientSocket = new Socket("localhost", 4444);
                in = new BufferedInputStream(clientSocket.getInputStream());
                /*receive the byte*/
                int receive1 = in.read();
                System.out.println("The received message #1 is: " + receive1);
                /*receive the string up to the line termination*/
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                int c;
                while (((c = in.read()) != '\n') && (c != -1))
                    baos.write(c);
                String receive2 = baos.toString("ISO-8859-1");
                System.out.println("the received message #2 is: " + receive2);
            finally
                try { in.close(); }
                catch (Exception e) {}
                try { clientSocket.close(); }
                catch (Exception e) {}

  • Photo books - many different sizes not possible?

    Hi. Does Elements 9 really offer only two sizes for photo books?
    I want to produce a photo book with multiple pages. But Elements 9 (German version) offers only two sizes:
    297 mm x 210 mm (A4)
    300 mm x 300 mm
    Above those two sizes i see the words “Print locally” (in German). These words “Print locally” cannot be changed. (I have an A4 printer installed.)
    I want to produce a PDF file in Elements and send it to an online printing service. These online printing services print photo books in many different sizes from PDF (i will not send it via Elements’ own system). Does Elements 9 really offer only two sizes for photo books?
    Am i seeing something wrong? I already changed the printer driver, checked preferences in Editor and Organizer, but found no way at all to get different sizes.
    Thanks for all hints!

    To merge the libraries manually use "File > Export".
    To save the high quality originals, set the export panel like this, with "Kind Original":
    If you have edited versions with added titles, caption, places, etc, use these export settings to save your work:

  • Excel attachment problems (different sizes)

    Hi,
    I want to send an attachments with an Excel File. I have no problem to send the message. Then I compose the same message with outlook with the same excel file like attachment but when I compare the two files there are differences (the excel file send by outlook have a different size, it's a little more big).
    Somebody know why?
    Thank you.
    Siddharta

    check them in SO01 tcode ??
    download that attachment to the desktop & open it from EXCEL- > file->open.
    what field seperator have you used in the program?
    regards
    srikanth
    Message was edited by: Srikanth Kidambi

  • Where do I find info on how to print on different size projects?

    I'm not sure if I'm posting this on the correct board or not. My question is where do I find instructions on how to print on different size papers such as, envelopes and postcards both addresses and return addresses. I know how to print the body of my postcards since I use Windows Publisher but I'd rather not have to use labels. It would be so much faster and more professional to print the addresses and return addresses directly on the postcards and envelopes. I've owned many HP printers and have always been able to do that but can't seem to set my Deskjet 8500 910A.
    Thanks for any help available.

    linadads,
    I am happy to help you with your issue regarding printing on envelops. The printer software doesn't carry the functionality to create envelope documents. You will use a word processor for completing this such as, Microsoft word. In Microsoft Word (or a like word processor) it will give you the option to create an envelope with the send from and send to address sections.
    I hope this helps
    ↙-----------How do I give Kudos?| How do I mark a post as Solved? ----------------↓

  • Mixing memory module of different sizes in G5-8 slot machine

    is there a problem with Mixing memory module of different sizes in G5-8 slot machine
    I have 2gb on four slots with 512 memory chips
    Can I upgrade my memory with 1gb chips in the remaining four slots.

    Hi epospiech-
    Yes you can.
    Instructions here: Memory (DIMMs) Replacement Instructions
    Luck-
    -DaddyPaycheck

  • In Pages 5, why are page thumbnails different sizes?

    So I'm using 5. And I must say I think it's brilliantly done after a long period of ******** about it. I guess I'm not asking of it anything it doesn't provide and what it does it does very well - though I'm puzzled by the behavior of selecting text via the keyboard.
    Anyhow, that's not my question. I'm working with a long text document. I notice that as I work the page thumbnails become different sizes. It's subtle but it's clearly intentional. I reckon it's trying to tell me something but I don't know what. Haven't been able to find any info in the manual and was wondering if any of you clever people here might know. Thanks.

    This is what I meant about how rude you are though.  Your answer DOESN'T EXPLAIN ANY OF THE BEHAVIOUR myself or the other person were reporting.  The only assumption that I can make is that you posted here for the sole purpose of implying that we are both mistaken or stupid. 
    How is this helpful at all? 
    How do you have 32,485 points when you are obviously more concerned with insulting people than helping them out?  It puts the lie to the whole idea of "Apple Support Communities." 
    Also, I specifically informed you that your comments were insulting and unhelpful and politely requested you not post on this thread anymore or at least until you had some kind of actual information, yet here you are.  Posting again, with no content other than the implied insult.
    I'm not stupid.  I know what a section break is, I know what a page break is.  I'm a writer who has used innumerable word processing programs over the years and have been an IT worker for 10 years now. 
    I have a Pages document.  It has no (or only one depending on your point of view), section(s).  It has page breaks only.  The pagination is set to start at "1" on the first page and proceed normally to the end of the document (300 or so pages).  I am using Pages 5.5.2 on a brand new iMac.  I have NONE of the previous or older versions/types of Pages on my computer. 
    The pages thumbnails on the side, do actually CHANGE SIZE randomly as I am editing the document.   These differing sizes are NOT CORRELATED WITH THE BEGINNING OR ENDING OF SECTIONS.  These size changes are also NOT CORRELATED WITH THE PAGE BREAKS (in case you were about to argue the similarity of page breaks and section breaks).  As I work through the document and scroll up and down editing here or there, the size of the thumbnails RANDOMLY CHANGE SIZE.  Sometimes this is correlated with me working on a section, sometimes I can work on a section and no change happens at all.  The thumbnails that change size often change back again when I scroll back to them later on. 
    So please ... Try to act like a decent human being and either help out, or go away.  STOP POSTING THAT WE ARE WRONG, when you DON'T in fact know we are wrong.  STOP INSULTING ME by assuming I am stupid. 
    Why are you even here if you don't want to actually HELP anyone? 
    To anyone else reading this:  I am having a real bad time with this fellow who is just the most insulting person I have met for a while, however many of my posts about him are being deleted.  If anyone knows (including the mods of this forum) of the proper way to REPORT or get rid of a troll/abuser like him on Apple Support Communities or a place to report his behaviour, please let me know. 

Maybe you are looking for

  • How to repaint a component when it moves?

    Hello, I have an application with many JPanels packed together, and one of them has a picture that I render with the paint() method, using the coordinates of the panel as reference. For example, suppose I were to draw the diagonal: Dimension d = getS

  • Upgrade SCM  4.1 - 7.0  issues

    Dear All, We have just Upgraded our Devolopment System from SCM 4.1 to 7.0.... After that we have run " RS_BW_POST_MIGRATION" for activating the BI objects... After that we run the MPOS and Planning area Consistency Check... When i load the data in t

  • Kernel bugcheck (or "Blue Scree

    *** STOP: 0x000000D (0xF8CEA200,0x00000002,0x0000000,0xAAE2D6B3)*** ctac32k.sys - Address AAE2D6B3 base at AAEE000, DateStamp 4039a8b9 Should I post this here? I emailed support about this and it's turned into a wierd mistake. Currently they are maki

  • In LIKP, which field indicated that this order is an inbound delivery or ob

    Hi, In LIKP, which field indicated that this order is an inbound delivery or obound delivery... Thanks!

  • TS1702 Apple update App not working.

    You know the area in the App Store where you update your apps, it's not working. It's shows the # of apps to be updated, but it does have the apps in the update window, it's just blank. So I'm not able to update my apps. I've turned my phone off and