Sending /receiving object data from JavaNIO bytebuffer

Hello All,
i have designed a real time Physics simulation with javanio , which is about moving balls simultaneously (real time) on multiple clients.
Currently, i m sending the coordinates of one ball with string parsing, but now i want to move multiple balls and want to have some generic mechanism other than sending string, so i create 4 balls on server.
my design with string base is already running (one ball which is running from server, receiving coordinates as string on clients now i want more balls so i have problem to send the coordinate for each ball and receiving the same on client to draw while there are no reference attach to those which ball correspond to which ball on client) but i need little bit generic solution which can be valid for other simulations too.
This should be realized by sending the reference of each ball but i don't have idea how to realized that with java byte buffer and with javanio overall.
how i can realized, so that coordinates of each ball correspond to same ball on client (which i created on client too), and each ball can be move according to its received coordinates from the sever.
I have the problem with implementation, if somebody help me with code example , it would be great, anyway which can be generic for sending simulation data like object coordinates other than strings can be acceptable(if somebody did similar work) but it should implement the usecase as i described.
Thanks,
Jibbylala
PS: i saw this post:http://www.coderanch.com/t/276259/Streams/java/Convert-ByteBuffer-object
they are sending the whole object but i just wanted to send
Ball.X ,Ball[i].Y and receive the same at client sit
Edited by: 805185 on Mar 20, 2011 8:29 PM

I think the question here is that if you have n balls on the server, and you receive coordinates on the client, how the client will know for which ball the coordinates are meant. The answer is pretty simple: just modify your protocol to send the ball number before you send the coordinates. You say you currently use strings to represent the coordinates. Say your string currently looks like this: x|y, where x is the x-coordinate, | the separator and y the y coordinate. You could modify this string as follows: n|x|y, where n is the ball number, x the x coordinate and y the y coordinate. This way the client knows for which ball the coordinates are meant.
If you want to avoid the string parsing, use the ByteBuffer.putDouble() and ByteBuffer.putInt() methods as suggested by EJP.

Similar Messages

  • Can't receive the data from my hardware device by LAN

    Hi!
    background:  For a testing task, I set up a hardware testing platform that including of a power supply device, a hardware to be tested(Device Under Test), a power Meter and a PC.   i build a program to control the hardwares, and they communicate with each other by LAN. at first, the program as a client can normally communicates with my hardware after initializing all hardwares. And then the program turns off the power of my device and turn on power again after delay 60 seconds. after initiantion, my hardware can execute the command which is received from the program, but the program can't receive the data from my hardware. Why my program cannot receive the data from my hardware, after the second time turn on the power of my hardware?  the program as client code as below:
    int CVICALLBACK ClientRRH (unsigned handle, int event, int error, void *callbackData)
      char temp[64]={0};
      int  ReceiveSize=0;
      char *Pos;
      switch(event)
       case TCP_DATAREADY:
        if( (ReceiveSize=ClientTCPRead (rrhHandle, readRRHBuffer, 4096, 2000))<0)
                     SetCtrlVal (panelHandle, PANEL_TEXTBOX_INFO,"Read RRH trace error!\n");  
                    return 0;
        else
         if (ReceiveSize>4096)
          readRRHBuffer[4096]= '\0';
           else
           readRRHBuffer[ReceiveSize] = '\0';
        if (Flag)
          Pos = strstr(readRRHBuffer,orderString);
          if(Pos)
           //strncpy(temp,(Pos+ strlen(orderString)),maxSize);
           _mbsnbcpy(temp,(Pos+ strlen(orderString)),maxSize); 
           sprintf(receData,temp);
           *temp=0;
           Flag=0;
           maxSize=0;
           *orderString=0;
        SetCtrlVal (panelHandle, PANEL_TEXTBOX_INFO,readRRHBuffer);
        *readRRHBuffer=0;
                break;
             case TCP_DISCONNECT:  
       rrhHandle =error;
                SetCtrlVal (panelHandle, PANEL_TEXTBOX_INFO,"TCP Clienterver has closed connection!\n");                 
                SetCtrlVal (panelHandle, PANEL_LED_RRH, 0);      
                break;
     return 0;
    int RRH_ini(char *RRH_address)
        ViChar Buffer[200];
        char temp[200];
        int status =0;
     if((ConnectToTCPServer (&rrhHandle, 7006, rrhAddr, ClientRRH, NULL, 1000)<0))
         SetCtrlVal(panelHandle,PANEL_LED_RRH,0);
        SetCtrlVal(panelHandle,PANEL_TEXTBOX_INFO,"Connection to RRH fail...\n");
         else
         SetCtrlVal(panelHandle,PANEL_LED_RRH,1);
         SetTCPDisconnectMode (rrhHandle, TCP_DISCONNECT_AUTO);
         sprintf(RRHCommand,"%s\n","asb");
         ClientTCPWrite (rrhHandle, RRHCommand, strlen(RRHCommand), 0);
         Delay(0.2);
         sprintf(RRHCommand,"%s\n","asb#1234");
         ClientTCPWrite(rrhHandle,RRHCommand,strlen(RRHCommand),0);
         Delay(0.2);
         SetCtrlVal(panelHandle,PANEL_TEXTBOX_INFO,"Connection to RRH successful!\n");
       return 0;

    Yes that's exactly my problem. The reader sends bytes but without a delimiter. So for example the greeting message I've mentioned earlier "iiAWID..." happens to be 32 bytes, therefore I made the following changes to the code:
    public void receive(int x){     // x = expected length of bytes being received
    boolean done = false ;
    int limit = x ;
    int counter = 0;
    try {           
    while (!done)
    if (in.ready())
    buffer.add(in.read()) ;
    counter = counter + 1 ;
    if (counter == limit)
    done = true ;
    }catch(IOException e) { // some code for handling}
    and this works fine, however, I'll probably have problems reusing this method later on, because some commands that I will send to the reader will result in responses of indefinite sizes. So I may have a response of length 12 one time and of length 8 the other. but between each response there's a maximum delay of 100ms... is there any way I can utilize that piece of information to improve my code?

  • Receive POST data from another URL and process using Struts

    Hi there
    We have a website and as of now we are receiving some data from another URL which is received as an appended part of the URL. My application uses Struts and we process the received data and send back a response.
    Now my question is, I have been asked to change this behavior because there are more parameters now which cannot be passed through the URL. I am supposed to get the data from the other URL as POST data (as a form) and I have to create a new Struts action to receive this data, process it and send the response back to the requesting URL.
    Please explain me how to do this using some example code snippets.
    Thanks a lot

    Lookup in XI is used to call the target data storage system and get data from there to your mapping programme.
    In XI you can do Lookup in Message Mapping, Java Mapping and in XSLT Mapping. Previously Lookup in XI was system dependent. But now what ever the system are i.e. SAP system or non-sap system(Oracle,MS SQL etc) lookup API are same.
    Overview of Lookup
    - Lookups are used to identify/request the data from mapping program.
    - It interrupt the process and looking for data which was stored in target system.
    - It get that data and comeback to process and continue with that data.
    Types of Lookups in XI
    - JDBC Lookup: JDBC lookup is used for accessing data from database (non SAP).
    - RFC Lookup: RFC lookup is used for accessing the SAP Data.
    - SOAP Lookup: SOAP lookup is used for accessing data from Webservice
    Steps to perform Lookup in Mapping
    Import package com.sap.aii.mapping.lookup.*;
    Create connection to the target Database system.
    // Determine communication channel created in ID
    Channel channel = null;
    channel = LookupService.getChannel("DB-SYSTEM-NAME","DB-CHANNEL-NAME");
    // Get system accessor for the channel.
    DataBaseAccessor accessor = null;
    accessor = LookupService.getDataBaseAccessor(channel);
    Build the Query String.
    Getting Result
    // Execute Query and get the values.
    DataBaseResult resultSet = null;
    resultSet = accessor.execute(Query);

  • HT4061 I recently switched from my iphone to a samsung Galaxy S4, trading in my iphone. I now can not send/receive text messages from any iphones to my galaxy S4. Since I traded the iphone in, I can't access it to make any changes. Any ideas?

    I recently switched from my iphone to a samsung Galaxy S4, trading in my iphone. I now can not send/receive text messages from any iphones to my galaxy S4. Since I traded the iphone in, I can't access it to make any changes. Any ideas?

    http://support.apple.com/kb/TS5185

  • Function Module to send Vendor Master Data from SRM to ECC

    Hi Guys
    I heard there is a function module in SRM which can send Vendor Master Data from SRM to ECC please confirm for me if there is such a function Module and what is it called. Thanks

    Hi,
    Vendor Master data is replicated to SRM from ECC. Standard Transactions (BBPGETVD,..) will be used to replicate the data from ECC.
    Vendor Master will exists in ECC, so there is no point in sending the same back from SRM to ECC. If the requirement is the other way around, we can use the transaction BBPGETVD in SRM system.
    Hope this helps.
    Regards,
    Hemanth

  • Sending attachments/binary data from flex to Restful APIs

    Hi,
    We have a requirement of sending the files (or binary data) from flex GUI to Restful services(backend APIs). We are using flex HTTPService component to invoke the rest apis. The Rest APIs are designed to accept the multipart/mixed data which can support the binary data as well.
    Can any one help us understand, how can we send the multipart/mixed OR multipart/form-data  from flex to backend using the HTTPService. Or is there a better way to send the mixed data from Flex GU to Restful APIs.
    Request you to please respond to this at the earliest as this is very urgent.
    Thanks and Regards,
    --Revanth

    Has anyone worked on this issue?? i wanted a quick response as we are in the middle of the development and this is a r
    equirement
    Thanks
    -Revanth

  • Sending & Receiving compressed Data

    Hi, How can i send & receive compressed data over a network using DeflaterInputStream and InflaterOutputStream, thanks.

    You probably would not use those classes directly, but GZIPInput and GZIPOutput stream instead. you would wrap those streams around the socket Input and Output streams at either end of a socket connection.

  • Can anybody tell me how to send/receive  the sms from java application

    Hi All,
    Can any body tell me, how to send/receive the sms from java application to mobile phones.
    I have installed the jsms engine and when i try to connect to the mobile device ,the jsms server is giving
    the following error.
    Cannot connect to GSM Device, error : -11

    Which jsms? Google finds several.
    Try the website where you downloaded it.

  • Can any body tell me, how to send/receive the sms from java application

    Hi All,
    Can any body tell me, how to send/receive the sms from java application to mobile phones.
    I have installed the jsms engine and when i try to connect to the mobile device ,the jsms server is giving
    the following error.
    Cannot connect to GSM Device, error : -11

    The best place to ask your question is at the JSMS website, forum or mailing list since this is no error that directly comes from a class belonging to the core Java classes.

  • When sending/receiving an iMessage (from gmail address) how can I then receive or access my iMessages on my actual gmail account/inbox?

    When sending/receiving an iMessage (from gmail address) how can I then receive or access my iMessages on my actual gmail account/inbox?

    Hi,
    The Messages app can join 5 different services.
    The "iChat Originals" that include AIM, Jabber and Yahoo (although they were added at different times to the app)
    The Bonjour account that has been present for LAN based Mac to Mac chat and lastly the iMessages account in the Messages app that iChat has become.
    Google email IDs can be used as a Jabber ID in Messages as Google run a Jabber server.
    As the Google server does not follow conventional naming formatting it has it's own Add option in Messages.
    Effectively all the services are separate.
    Any email used as an Apple ID can be the iMessages account.
    Of course this may be a Google one like you have that can also be used as  Jabber/GoogleTalk ID or it may be an Apple issued ID (@mac.com @me.com or @icloud.com) that will also work as a Valid AIM Screen Name.
    It may be that someone has their Yahoo email as their Apple ID.
    8:35 pm      Monday; August 11, 2014
    ​  iMac 2.5Ghz i5 2011 (Mavericks 10.9)
     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

  • Classifier mapping to read Sender & Receiver  Identification Number from XML. How to handle in B2B Add on

    In current See burger tool, We have this functionality to read Sender and Receiver Identification number from the XML. Is there any way in b2b add on to do this.

    Hi,
    The classifier within the Seeburger context is being used to call your parent mapping, in case you want to dynamically determine your mapping, based on data in the UNB/UNH segment.
    Within the B2B add-on, there is no need to.
    Only use module localejbs/EdifactConverterModule in case you want to convert to or from EDI.
    You have a specific requirement or do you want to test something out?
    Kind regards,
    Dimitri

  • Receive LV data from another computer

    Dear
    I would like to write Labview program after receiving some data.
    The data(temperature and humidity) are acquisiting in real time by LV from an independent computer(remote com.).
    Are there some simple methods to share or extract the data like this situation?
    (Hopefully, I don't want to modify much LV code in the remote computer.)
    Thank you in advance. 

    For DataSockets, you have to be running Windows, the DS server doesn't run on other platforms.You have to already have TCP network access between the two machines.
    For this little exercise, the data you want must be in a front panel indicator (or control). If you do more coding, you can send DS data programmatically, but for now, let's assume it's on the panel.
    On the client side (the one you will monitor with), run the DS Server. {Start - Programs - National Instruments - DataSocket - DataSocket Server.
    On the Server side (the one where the data is already there), pop up on the item(s) you want to monitor.
    Choose DATA OPERATIONS - DATASOCKET CONNECTION.
    In the CONNECT TO box, enter "dstp://192.168.0.101/Value1" (without the quotes). Substitute the client IP # for the IP # shown. Substitute a sensible name for the "Value1" part.
    Choose PUBLISH as the connection type, an click ATTACH (or CHANGE if this is not the first time thru).
    You should see a small LED next to the item. You can hide it if you want (VISIBLE ITEMS), but for now leave it there.
    Run the program. The LED should be GREEN, and on the client side, the DS SERVER should show changing numbers, as packets come in.
    On the CLIENT side, you want a similar indicator (same data type) as the one on the server that you are monitoring. You want a WHILE loop with a STOP button and a WAIT function, at least.
    On the front panel, pop up on the indicator, and choose DATA OPERATIONS - DATASOCKET CONNECTION.
    in the CONNECT TO box, enter "dstp://localhost/Value1". You could enter the IP number, but "localhost" covers it, since the DS server is running on this same machine. The "Value1" part must match the name you gave it on the other (server) end.
    Click SUBSCRIBE, and close the dialog.
    Run your client program, and the client's indicator should match the server's.
    Things to be aware of:
    You don't know when the data is updated. When your client program uses the values, it gets the latest values. Maybe they're a mSec old, maybe they're a month old. You don't know.
    If you monitor TWO (or more) indicators, they are not necessarily updated at the same time. If you read them on the client, maybe they correspond, and maybe they don't. It's possible that you read them AFTER it updated #1, and BEFORE it updated #2. You just don't know. If that's a problem, put everything into a cluster, and just update the one value.
    The server will consume system resources (CPU - network time) and net traffic, whether you are listening or not. If your server updates the display 100 times a second, but you only want a value once a second, that's wasteful because the value gets sent over the net 100 times.
    I'm not 100% sure, but I think there's no security with this. Any process with access to the DS server, can ask to be updated and it will be.
    You had asked for a minimum-code-change idea. I believe the above meets that challenge (no code change at all, only DS settings).However, it has drawbacks, and if they outweigh the no-code-changes, then you need to consider either programmatic DataSockets or plain TCP. With those you can control every aspect of communication. Consult the examples for those.
    Message Edited by CoastalMaineBird on 04-01-200704:51 PM
    Message Edited by CoastalMaineBird on 04-01-2007 04:53 PM
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks
    Attachments:
    DataSocket.png ‏41 KB

  • I can call out but all incoming calls are going directly to VM with no signal that I missed a call or have VM. I can send/receive text messages from other iPhone/iPad/iTouch users, I am assuming this is really "iMessage." Is it apple software?

    I have spent hours on the phone with Apple and AT&T. I went thought reset, on/off, etc, etc with both companies to no avail. Each company pointed fingers at the other....as being the source of the problem.
    Problems: Suddenly ALL  incoming calls were going directly to VM with no signal I missed calls and/or had VM. I was also unable to receive all Text Messages...Oddly, I could send text messages to anyone (even non-apple users but I could not receive their responses)........then I when I got home I started receiving text messages from other apples users ONLY. I assume now - iMessage kicked in and I could text (send/receive)  other iPhone/iPad/iTouch users ONLY. ....yes, I could still (send) text messages to my husband's blackberry (he received my messages fine) but my phone would NOT receive his text respones.
    Finally, I googled the problem and found this community where other people have had the exact same problems! One person said he "turned off 3 G" which was the solution for him....so I did the same and VIOLA! My problem  solved! Nevermind the fact that I pay for 3G and cannot use it....so here's my question, if 3G is the problem on my phone is this an APPLE issue or a NETWORK problem? Do I purchase a new phone and slip in my same SIM card and hope the same does not occur or do I get a whole new SIM card and phone? What is the long term resolution to this problem?
    I am happy however to find that my problem is NOT an isolated incident and wish Apple or AT&T had told me this is not so uncommon because I thought (based on the baffled response from Apple) that this has never occurred before.  Where is Steve Jobs when we need him?

        jsavage9621,
    It pains me to hear about your experience with the Home Phone Connect.  This device usually works seamlessly and is a great alternative to a landline phone.  It sounds like we've done our fair share of work on your account here.  I'm going to go ahead and send you a Private Message so that we can access your account and review any open tickets for you.  I look forward to speaking with you.
    TrevorC_VZW
    Follow us on Twitter @VZWSupport

  • Web Service receives no data from Stored Procedure call.

    Issue: When calling a Stored Procedure from a Web Service no data is returned.
    Lead up: I can call the SP 100 times a day for 3-4 days then for some reason the Web Service no longer get the data from SQL. I have ran a trace and I can see the SP running though all of its steps and returning the data, but the Web Service
    is not getting it.
    Fix: None yet.
    Work around: Before the Web Service calls the SP, I am sending an SP_Recompile to the SP in question. For now this seems to have resolved the issue.
    Detail: 
    1. SP is querying data from another DB on the same server.
    2. SP is storing query data in Temp Tables.

    Hello,
    Does your Stored Procedure have parameters? If so, the issue may be cause by parameter sniffing. Please refer to the following blog about Paraemeter Sniffing:
    http://www.sommarskog.se/query-plan-mysteries.html
    The recommended fix for most situations is to not use parameters directly in queries, but rather store them into local variables and then use those variables in the queries.
    Regards,
    Fanny Liu
    If you have any feedback on our support, please click here.
    Fanny Liu
    TechNet Community Support

  • Send Ex factory date from R3 to APO and populate in PO in APO as start date

    Hi ,
    Need your expertise in one scenario. SAP IS retail is combined with SAP APO.
    1) Purchase Order is ciffed to APO.
    2) Based on delivery date in PO in R3....APO calcualated date for distribution demand at source location by taking lead time from tlanes
    2) Requirement is to extract  'Ex factory date' from table EXPD in R3 and then send this date to APO.
    3) This new date should replace the starting date of PO in APO...in keyfigure Distribution demand at source location.
    Could you please suggest the way to do it? Will appreciate your response.
    Thank you in advance.

    Hi Aparna,
    Thanks.
    I have also started with purchase order user exit (CIFPUR01  Exit Function Module- Exit_SAPLMEAP_001)  at CIF outbound in R3 which will capture the date from table in R3..WIll be sent to APO...APO inbound user exit( APOCF006 ( Functional Module EXIT_/SAPAPO?SAPLCIF_PU_001) will overwrite the date at soucre location in key figure Dist Demadn TLB Confirmed or by chaing date at order level.
    Hi Experts,
    I think there are two more points....
    1) If dates are changed in table ( EXPD) then change pointer will not trigger CIFFIng thsoe changes to APO as the field is not CIF relevant. So it wont be real time integration. Work around can be to set up CIF batch job for PO at regular interval. But I am wondering if we can get some way to make it real time integrationj through CIF. Will appreciate reply on this.
    2) Have one more concern and I think its bit crucial to know the answer at this stage ....if date change in key figure Distribution Demand TLB Confirmed figure  happens in such a way that lead time between date at soucre and at target doesnot match with available Means of Tranport(MOT) lead times in TLanes then what will happen? WIll it rescheudle the dates as per date at target loctaion to match with lead time in Tlanes or will it not touch it? WIll appreciate reply of experts on this and also on how to achieve this in APO
    Thank you.
    Best Regards
    Nils

Maybe you are looking for