Sending data through network takes forever

hi fellow java developper
i'm developping a program that hides files contents trough xml messages in order to exchange securily from a intranet to an extranet whitout having to use ftp and port 21. The problem is it takes over 22 seconds to send a 22k from the server and it takes about 85 seconds to receive it on the client side. this is driving me nuts because i know that delay is extremely high. IS there a way to optimized those to following methods so that the delay is reasonnably cut down
thanks in advance
here is my code to send and receive data,
private BufferedInputStream inBuffer; // input buffer
private BufferedOutputStream outBuffer; // output buffer
* Method to send a String to the client
* @param content is the string to send to client
public void send(String message) throws IOException
ByteArrayOutputStream streamOfBytes;
     DataOutputStream insStream_Out;
     streamOfBytes = new ByteArrayOutputStream(message.length());
insStream_Out = new DataOutputStream(streamOfBytes);
     for (int i = 0; i < message.length(); i++)
          insStream_Out.write((byte)message.charAt(i));
     outBuffer.write(streamOfBytes.toByteArray(), 0,streamOfBytes.size());
     outBuffer.flush();
     * This method permit reception of string messages
     * @param a single character identifying the terminator to avoid receiving garbage
     * @return a string containing the message
     public String receive(char terminal) throws IOException
     char c;
     String message = "";
long start = System.currentTimeMillis();
int i = 0;
     while ((c = (char)inBuffer.read()) != terminal)
     message = message + String.valueOf(c);
i++;
     long end = System.currentTimeMillis();
System.out.println("temps requis recevoir:" + (end - start) +" ms nbboucle:"+i);
return message ;
     }

Hmmm.. there are a few optimization possibilities here, both with respect to creating bytes and retrieving text from bytes again. This is more close to the way java does it, and also the recommended way:// Push data out to a byte[] like this:
String data; // initialized elsewhere
ByteArrayOutputStream target = new ByteArrayOutputStream( data.length() );
DataOutputStream stream = new DataOutputStream();
stream.writeUTF( data );
stream.flush();
byte[] bytes = target.toByteArray();
// Read data in from an InputStream like this:
InputStream input; // initialized elsewhere
DataInputStream stream = new DataInputStream( input );
StringBuffer result = new StringBuffer();
try
   // terminates with an EOFException
   // (ridicolous, but that is what the specification says...
   while( true )
      result.append( stream.readUTF() );
catch( EOFException e )
return result.toString();However, if your code works, the times you talk about is probably not connected to bad code (unless your XML is really really big) but more likely to network problems. Note that if your output string results in a byte array larger than 65535 bytes, a DataFormatException will be thrown from writeUTF (so the method fails). In that case, you will have to use OutputStreamWriter / InputStreamWriter and specify encoding to be e.g. UTF-8.
Good luck!
Daniel

Similar Messages

  • Sending pic's through email takes forever. Have yahoo.

    Sending pics thru emaul takes forever. I have yahoo account. Anybody have idea's whatmight be causing this.

    here are some ways to troubleshoot the spinning beach ball: http://www.macworld.com/article/151583/2010/05/spinningbeachballofdeath.html  Hope you find this useful.

  • Sender sending data through XML, How to process it in ECC (No PI involve)?

    Hi,
    The sender system sending data through XML tag and that need to be processed in SAP side.
    How it can be done without involving XI or IDoc?
    Is it possible through HTTP post?
    Sample XML Transactions
    1. SAP Availability Transaction (Request)
    <?xml version="1.0" standalone="yes"?>
    <ECCAVAILREQUEST>
    <AVAILTEXT>CHK STATUS</AVAILTEXT>
    </ECCAVAILREQUEST>
    2. SAP Availability Transaction (Response)
    <?xml version="1.0" standalone="yes"?>
    <ECCAVAILRESPONSE>
    <AVAILTEXT>OK</AVAILTEXT>
    </ECCAVAILRESPONSE>
    3. DUMMY_SYSTEM PO Transaction (Request)
    <?xml version="1.0" standalone="yes"?>
    <DUMMY_SYSTEM REQUEST>
    <CREATEPB>1</CREATEPB>
    <POORDERDATA>
    05607015156070151TORDAEHTWW05727500002D0979054+
    </POORDERDATA>
    4. DUMMY_SYSTEM Order/Inquiry Transaction (Response)
    <DUMMY_SYSTEM RESPONSE>
    <C_PO>99999</C_PO>
    <RETURNDATA>
    DAT&#13;&#10;
    </RETURNDATA>
    </DUMMY_SYSTEM RESPONSE>

    Hi,
    check this link
    http://help.sap.com/saphelp_nw04/helpdata/en/21/e9c97ceb1911d6b2ea00508b6b8a93/content.htm
    this is for processing inbound IDOc through XML-HTTP(Inbound) port
    like this there should be an option for reading files placed by HTTP_POST.
    in SICF transaction there should be a service to do that.
    defaulthost -> sap-> xi-> adapter_plain. i know you don't have XI in your landscape but this is the component which be responsble for receving messages over HTTP_POST.
    look for a program which can access messages from there.
    please check with your basis team
    Suresh

  • Send encryption data through network

    I'm doing encryption data exchanging project. I can describe my scenario anyone can give me good suggestion.
    I use RSA Key pair. Client side encrypt the data using private key and server decrypt those data using particular public key. I store my keys in keystore. For one attempt I use public and private keys belong to one alias. My problem is when doing decryption in server side I got error message (BadPaddingException: Data must start with zero). But if I do encryption and decryption in same class using same keys without any client/server connection it works properly.
    So, if anyone can give me any advice or suggestion, I'm very appreciat

    ivanovpv wrote:
    I think problem is somewhere in data transmission. During transmission either server or client adds extra padding information.No. For symmetric block based encrypted the clear text has to be padded to make it a full block. This is normally done as part of the encryption process using PKCS5 padding. Padding is also reqired for RSA encryption so as to make sure the cleartext ^ public_exponent is greater than the modulus. This is normally done using PKCS1 padding.
    If the encrypted data is corrupt then one normally gets a exception such as BadPaddingException when decrypting using a symmetric algorithm or an exception indicating that the padded data should start with a zero in the case of RSA encryption.
    It is almost certain that the OP has corrupted his encrypted data or his key, possibly by converting to a String without using Hex or Base64 encoding. Without seeing his code we will probably never know.
    >
    I would suggest just get your public key (i hope it's just a long/String probably wrapped within some class) then explicitly convert it into character array (best is to use UTF-8 encoding) - then transmit through network. On other side decode from UTF-8 character array into long/String - probably you'd need to instantiate public key object from your long/String and enjoy!String should never be used as a container for binary data and keys are binary data. Just converting them to a String specifying utf-8 will almost certainly corrupt them. If one must have a String version of any binary data whether it be a key or cipher text one should reversibly encode it using something like Base64 or Hex.

  • Sending Data Through a Output Stream...

    Hello,
    I am writing a program that works on a network...a server is running and client will connect to the server and send specific data for the server to complete transactions on.
    The transactions that are mainly seen are SQL SELECT statements and as you can imagine a statement could bring back many records.
    At present I have been able to send specific data through streams and have turned this into parameters on the server side and performed SQL. What I need help with or suggestions on is how to get the data back to the client. In some cases it may need to be displayed on screen or just used for further processing?
    Please let me know if this is not 100% clear.
    Thanks,
    P

    If you are able to send data over a network, then I assume that you know how to do network programming in Java, as well as knowing SQL.
    Java has JDBC - Java DataBase Connectivity API that supports your requirements in full.
    If you require a custom solution, then you need to be able to read data back from the server - when the server returns the ResultSet back to the client.
    A Socket object has both input and output streams. Seems that you know about the output stream, do you not know about the input stream?
    If the server is setup to send data back to the client over the same socket, then you should simply be able to read the results back from the socket's input stream.

  • Problem in sending data through email in brodcasting

    HI All
    i am trying to send the data through email in the broadcasting. but as i execute the broadcasting the message comes
    "Online processing is not possible for user 1"
    further its is saying
    "You want to execute a broadcast setting online. Processing this setting requires switching to another user (for example, with the user-specific precalculation of Web templates for a user other than your user). This is only possible in background processing."
    but i dont know how to login as seperate user. as i have to send the data through my login and not someone else.
    Hope i am clear.
    Please help me on this its very urgent
    Thanks

    The solution to this problem is that:-
    1. this is not an error
    2. it gives the warning beacuse we cannot execute the broadcast setting at that moment (with different users in reciepient list) i.e. we have to schedule the broadcast settings.
    Thanks
    Prat

  • J2ME app.: To update Oracle table by sending data through mobile phone

    Hello all,
    I want to develop a mobile app to update the table of oracle database by sending the data through the SMS (Short Message Service). Means I'll send a sms through my cellphone containing some data and this data will be used to update the remote oracle database. How to do that?. Plz help.
    Thanx in advance.

    hi
    My problem is here I need to update the loginfo table with the file name, count of records, table name and datetime.
    For instance my dat file is XX.dat
    my database table name is Mytable
    Total record count is 10,00,000 records
    datetime as on this date
    the data in the XX.dat file I am using the controlfile (SQL*loader and dumping into the Mytable.Now my 10,00,000 records are dumped into the Mytable.
    This process information I want to store it in the loginfo table. For this I need the trigger
    CREATE OR REPLACE TRIGGER MYTRIGG
    AFTER INSERT ON MYTABLE
    Declare
    V_Count Number;
    Begin
    Select count(*) into V_Count from Mytable;
    Insert into Loginfo(TotalRecords,Date)
    Values(V_Count,Sysdate);
    end;
    This is the trigger I have used.But in my loginfo table instead of one value as 10,00,000 it is getting each record as row by row
    1
    4
    100
    1000
    10,00,000
    So I need only one value to be stored and at the same time my tablename and filename must also be stored.
    Kindly help me
    suroop

  • Sending data through a serial write box (vision processing)

    Hi there, I am fairly new to labview and vision assistant. I was wondering if I could get some assistance on a particular problem we are having with our project. The idea is that we will use a webcamera to analyze a continuous loop of images and identify shapes, then send the data through the serial port to a controller which uses the mint motion language. The problem we are having is we cant sind a way to send the data we are getting from particle analysis to the serial port. Is there any way we can do this? I would be eternally grateful for any kind of pointers!
    I will attach the write to box we are using right now as well as the program itself
    Attachments:
    bild.vi ‏104 KB
    SKRIV2BOX.VI ‏31 KB

    What you are searching for are the functions "Flatten To String" and "Unflatten from String".
    Attachments:
    FlattenToString - UnflattenFromString.vi ‏16 KB

  • IPhone Charging through computer takes forever

    I have tried both ways of charging my iPhone, through the computer and through the wall plug.
    Charging through my computer (Powerbook G4) takes forever and never reaches full charge, even when left over night.
    When I plug it into the wall, it will reach full charge in a normal time
    any ideas?

    You do not specify which model of the G4-based PowerBook you are using, but models with USB 2 ports did not ship until September of 2003, when the PowerBook (12 inch G4 DVI), PowerBook G4 (15 inch FW800) and the PowerBook (17 inch 1.33 GHz) units were released.
    If you have anything earlier, you have USB 1.1 ports, which are quite likely the cause of your battery recharge issues.

  • Problems in Sending Data through JMS Bridge - WLS 10.3 to WLS 11g

    I have a scenario where I need to send data from a queue configured on WLS 10.3 to WLS 11g. I am using OSB on WLS 10.3.
    What I have done is
    1. Created a JMS Based BS in OSB which sends data to jms://localhost:7001/ConnFactoryJNDI/QueueJNDI
    2. Created a JMS Bridge on WLS 10.3
    3. Source Destination has been configured as the one mentioned above.
    4. Target Destination has been configured to a queue on WLS 11g.
    When i execute the JMS Based BS in OSB, data is being written to the Source Queue directly. I am not sure of the JMS Bridge functionality but I assume that once data is written to the Source Destination, that data will be automatically pushed on the target destination.
    I have configured a JDBC store for the target queue but I no table is created with the data sent from the source.
    M i missing something here?

    I think this question belongs to weblogic server, but as far as I know bridge should be created always at higher version. means, you should create bridge at 11g and try to pull/drop data from 10g. To check any errors in bridge, check the server log and make sure status of bridge is "forwarding messages"
    Regards,
    Anuj

  • How to send data through gprs from j2me application to desktop

    hi
    i wanna send some data to a server(where http://localhost:8080/ccp.html is running).i wanna catch this data and use it further.
    how to do it through query string/xml.

    Hi srini,
    it depends upon what is the receiver system.If you want to save the emails coming from SAP to Files ..then u will have to use File adapter in the receiver side...
    check these weblog.....
    Receiving Mail attachments using additional files of file adapter
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1685 [original link is broken] [original link is broken] [original link is broken]
    Regards
    Biplab
    Use a Good Subject Line, One Question Per Posting - Award Points

  • Need to send data across network, what is the dataStructure for my data?

    using JXTA, i want to send file or messages among the peers.
    the data should contain the ACK

    Hello Dear Programmer Look please I need to know what is the data transfer Structure is to say make sent a sample Data structure
    to cross throughout Network
    to be compile in Java
    My Regard
    Alfonso Franco
    [email protected]

  • 'Preparing data for exporting' takes forever (Urgent, please help)

    Hello,
    I'm currrently editing a 1920x800 anamorphic Full HD project on Premiere Pro CS5. The original full HD clips were replaced with AE-comps using Dynamic link for color grading. The project is 15 minutes long and mainly consists of linked AE-comps. The sound is filled with gunshot sound effects, music and original recorded audio. That audio is also linked with Soundbooth for some postwork.
    Here's the problem: when i hit the 'Export' on Premiere pro I get the window, i choose my settings (H.264 10 mbps) and then when I hit the 'Qeue' button it shows the progress bar 'Preparing data for export' and Media Encoder starts up normally. The problem is nothing happens afterwards. The project doesn't get loaded in AME and the progress bar keeps on telling forever that it's 'preparing data for export' Normally this process only takes up a minute or 2 max. How can i fix this?
    Editing rig:
    27 inch imac
    4 gigs ram
    2.53 i5 processor
    ATI 4850
    Please help me with this, my deadline is within 4 hours
    Thank you!

    I have some suggestions you can try.
    1. Can you try exporting directly from inside Premiere, instead of adding to AME from PR?
    - press the Export button inside the Export Settings Dialog, not the Queue button
    2. Can you import the sequence directly into AME?
    - launch AME, File menu\Add Premiere Pro Sequence
    3. Try using a different format other than, H.264.
    4. Try using PR CS5.5. You can download the trial version and use it for 30 days.
    Hope this helps. If not, please re-post with test results.
    Thanks

  • Single source sending data through multiple messages to a single reciever

    Hi all,
    I am trying to implement the below scenario:
    - I am reading from table1 in a database using a sender channel1. Based on data retrieved, I perform a JDBC lookup on table2 (in same d/b) using a reciever channel2 in an UDF of a message mapping1.
    - The data retreived from table2 is mapped to an intermediate format1. A mapping between the intermediate format and target message type1 is performed and message is sent to the recieving system using a reciever channel3.
    - Now, I need to map data retrieved from table2 to different target message types1,2,3.. based on some criteria and send it to the same reciever. I intend to use a different target message type and intermediate format for every kind of data obtained from table2 and a corresponding mapping.
    I plan to do this without using a BPM. Is it possible? If yes, then are the 3 communication channels sufficient to achieve this or do I need to have more communicatin channels?
    Any help would be appreciated.
    Thanks,
    Amit

    This is pretty straight forward...
    change your design as folllowing :
    1. as you have both table 1 and 2 in the same database , you can directly write a join query to pick data from both the tables . this can be specified in the sender jdbc adapter
    so your source data type would be like
    row..0..un
    +f1(field from table 1)
    +f2( field from table 2)
    +f3(field from table 2)
    2. now just create 3 seperate mappings
    mapping 1 = between source structure given above and target MT1
    mapping 2= b/w source struc given above and target MT2
    mapping 3 = b/w source struc given above and target MT3
    3. use 1 receiver determincation ...1 interface detemination where you keep on adding the message interfaces and interface mapings created above..
    4. use 3 receiver agreemetns

  • After Bios Update through thinkvantage, takes forever for PC to be active

    Hi ,
    I just wanted to say after lenovo update's very useful update, my pc now takes a good minute after boot-up for it to be responsive. Now, after boot, the connecting to internet circle just spins and stops. during this time, nothing else can be opened. when i click on itunes, the win 7 icon shows that it is active and then it goes dim again as if it was closed again. nothing works until the network is connected.
    thanks for the update...not
    any suggestions to reverse this other than reinstalling win 7? or do i just have to deal with this inconvinence since lenovo doesnt realize their update actually messes up their systems?

    I would also report this to Lenovo since posting the issue on the forum is not the same as contacting them directly.
    You've not indicated which machine, configuration you have.  I would boot and go into the bios since it may have changed something. Save and reboot seeing how it is then.
    T520 Model 4239 Intel(R) Core(TM) i7-2860QM CPU @ 2.50GHz
    Intel Sandy Bridge & Nvidia NVS 4200M graphics Intel N 6300 Wi-Fi adapter
    Windows 7 Home Prem - 64bit w/8GB DDR3

Maybe you are looking for