String Data-Loss over Sockets

I have some code that sends strings through a socket to a C++ program on another machine.
The test strings I have been using are three characters long (i.e. 6 bytes). The buffer size I have put on the socket is 72 bytes, so I should have no problem writing these strings.
The first three strings always arrive at the other program fine, BUT after that, only a substring of each string seems to get through. I am absolutely certain that the strings are complete before I send them, because I print it to the screen at the same time.
I have tried change the style of output stream I use (I have used DataOutputStream, BufferedOutputStream, BufferedWriter, StringWriter, and PrintWriter. It still happens.
Can anybody tell me why this might happen?
- Adam

Without more info it is hard guessing. If you want
reassurance that it should work, then yes, it should
work.-(Well that's kinda what I'm looking for. I'm wondering if anybody knows of a reason why a C++ program (running in windows -- btw, not by my choice) would read the string differently than a java program?
For all the XxxWriter types you used, I hope you
declared the charset to be one that preserves the
2bytes/char you expect (UTF-8 and ISO8859-1 aren't).I haven't modified that from whatever default is set. This may be the probelm, I will look into that, thanks.
You certainly did not use the BufferedOutputStream
without somehow encoding the characters into bytes,
so how did you do? I'm not sure (it was last week that I tried it) but I think the BufferedOutputStream has a method writeBytes(String) that I used.
For DataOutputStream, I hope you
used writeChar, which guarantees that 2bytes/char are
send. Nope. I mostly tried to stick with methods that accept a String, so that I was sure that it was sent out in the right format to be read back in as a String. I wasn't sure what the actually format of a String is, when passed through a socket, specifically, if there is a terminating character (I know C uses a \0 to end the string). Is there any additionl info need to write a string to a socket?
If you did all this, ... well I would not
fiddle with the socket's buffer size.Sorry, but I may have to maintain a low buffer size, because these strings are not the only things being sent over this socket. Do you think the buffer size is affecting the problem. I wondered, but the buffer size seems more than large enough to send 3 character strings.
That's all that comes to mind. Did you try netcat
(aka nc) as a server to make sure the problem is not
at the receiving end?I haven't tried this yet, but I will if I can't figure this out. Unfortunately, I'm NOT the author of the code that recieves the data, and the guy who is has simply assumed that the problem is my fault (although he's never actually tested his code with the string data being sent before), and is not interested in checking to make sure he's done it right. I tried looking over his code, but he's got the input routine burried in an #include file that I don't have.
Thanks for the input, Harald. There are a few things there that I will look into.
- Adam

Similar Messages

  • Data "loss" over fibre network

    I am using an Xserve RAID directly attached to a fibre switch. Several workstations are then connected to the switch. After a short period of use the data on the RAID "disappears". Rebooting the workstation shows the data again. The problem does not occur with one computer connected. Accessing the data through one "server" over CAT5 also works. Can anyone suggest why this would be and how to fix it.

    Do you have all machines accessing the same volume on the XServe RAID?
    Unless you're running XSAN, that is not a supported configuration - each machine will asusme it has exclusive control over the volume and won't know or expect other machines to be making changes.
    If you're trying to share one RAID amongst multiple machines your options are 1) connect it to one machine and use a file sharing protocol such as AFP to share it to clients, 2) use XSAN and one machine to control access, or 3) divide the array into multiple slices and give each machine it's own piece of the RAID (rather than all reading the same slice).

  • How to send string data through socket!

    Is there any method to send string data over socket.
    and if client send string data to server,
    How to get that data in server?
    Comments please!

    Thank for your kind answer, stoopidboi.
    I solved the ploblem. ^^;
    I open the source code ^^; wow~~~~~!
    It will useful to many people. I spend almost 3 days to solve this problem.
    The program works like this.
    Client side // string data ------------------------> Server side // saving file
    To
    < Server Side >
    * Server.java
    * Auther : [email protected]
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Server extends JFrame
         private JTextField enter;
         private JTextArea display;
         ObjectInputStream input;
         DataOutputStream output;
         FileOutputStream resultFile;
         DataInputStream inputd;
         public Server(){
              super("Server");
              Container c = getContentPane();
              enter = new JTextField();
              enter.setEnabled(false);
              enter.addActionListener(
                   new ActionListener(){
                        public void actionPerformed(ActionEvent ev){
                             //None
              c.add(enter, BorderLayout.NORTH);
              display = new JTextArea();
              c.add(new JScrollPane(display),
                     BorderLayout.CENTER);
              setSize(300, 150);
              show();
         public void runServer(){
              ServerSocket server;
              Socket connection;
              int counter = 1;
              display.setText("");
              try{
                   server = new ServerSocket(8800, 100);
                   while(true){
                        display.append("Waiting for connection\n");
                        connection = server.accept();
                        display.append( counter + " connection is ok.\n");
                        display.append("Connection " + counter +
                             "received from: " + connection.getInetAddress().getHostName());
                        resultFile = new FileOutputStream("hi.txt");
                        output = new DataOutputStream(resultFile);
                        output.flush();
                        inputd = new DataInputStream(
                             connection.getInputStream()
                        display.append("\nGod I/O stream, I/O is opened\n");
                        enter.setEnabled(true);
                        try{
                             while(true){
                                  output.write(inputd.readByte());
                        catch(NullPointerException e){
                             display.append("Null pointer Exception");
                        catch(IOException e){
                             display.append("\nIOException Occured!");
                        if(resultFile != null){
                             resultFile.flush();
                             resultFile.close();
                        display.append("\nUser Terminate connection");
                        enter.setEnabled(false);
                        resultFile.close();
                        inputd.close();
                        output.close();
                        connection.close();
                        ++counter;
              catch(EOFException eof){
                   System.out.println("Client Terminate Connection");
              catch(IOException io){
                   io.printStackTrace();
              display.append("File is created!");
         public static void main(String[] args){
              Server app = new Server();
              app.addWindowListener(
                   new WindowAdapter(){
                        public void windowClosing(WindowEvent e){
                             System.exit(0);
              app.runServer();
    < Client side >
    * Client.java
    * Auther : [email protected]
    package Client;
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Client extends JFrame
         private JTextField enter;
         private JTextArea display;
         DataOutputStream output;
         String message = "";
         public Client(){
              super("Client");
              Container c = getContentPane();
              enter = new JTextField();
              enter.setEnabled(false);
              enter.addActionListener(
                   new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                             //None
              c.add(enter, BorderLayout.NORTH);
              display = new JTextArea();
              c.add(new JScrollPane(display), BorderLayout.CENTER);
              message = message + "TT0102LO12312OB23423PO2323123423423423423" +
                        "MO234234LS2423346234LM2342341234ME23423423RQ12313123213" +
                        "SR234234234234IU234234234234OR12312312WQ123123123XD1231232" +
                   "Addednewlinehere\nwowowowwoww";
              setSize(300, 150);
              show();
         public void runClient(){
              Socket client;
              try{
                   display.setText("Attemption Connection...\n");
                   client = new Socket(InetAddress.getByName("127.0.0.1"), 8800);
                   display.append("Connected to : = " +
                          client.getInetAddress().getHostName());
                   output = new DataOutputStream(
                        client.getOutputStream()
                   output.flush();
                   display.append("\nGot I/O Stream, Stream is opened!\n");
                   enter.setEnabled(true);
                   try{
                        output.writeBytes(message);
                   catch(IOException ev){
                        display.append("\nIOException occured!\n");
                   if(output != null) output.flush();
                   display.append("Closing connection.\n");
                   output.close();
                   client.close();
              catch(IOException ioe){
                   ioe.printStackTrace();
         public static void main(String[] args){
              Client app = new Client();
              app.addWindowListener(
                   new WindowAdapter(){
                        public void windowClosing(WindowEvent e){
                             System.exit(0);
              app.runClient();

  • Binary file transfert over socket : data corupted !

    Hi everyone,
    I am trying to transfert binary files over Socket (java.net) and I get corrupted data... I know the data I write in the Socket is ok and I wonder why I don't get it right at the end.
    Does anyone know about it ?

    Ok i have re-written it without the Packet class and it know works...
    I give my code in case someone would be interested.
    ENCODER :
    public class Encoder {
         // the file to send
         private File file;
          * Constructor of the Encoder class
          * @param path the path to the file to send
         public Encoder(String path){
              this.file = new File(path);
              this.encodeFile();
          * This method contains the connection an file tranfert code
         private void encodeFile(){
              try {
                   // opening file reading stream
                   FileInputStream fis = new FileInputStream(this.file);
                   // connection...
                   Socket sock = new Socket("127.0.0.1", 5698);
                   // opening an output stream
                   BufferedOutputStream bos = new BufferedOutputStream(sock.getOutputStream(), 1024);
                   // start time
                   long start = System.currentTimeMillis();
                   // setting up the buffer
                   byte[] buffer = new byte[1024];
                   /* ---- File Transfert Loop ---- */
                   // reading for the first time
                   int read = fis.read(buffer);
                   while (read > 0){
                        bos.write(buffer);
                        bos.flush();
                        read = fis.read(buffer);
                   /* ----End Of File Transfert ---- */
                   // end time
                   long end = System.currentTimeMillis();
                   // closing streams and connection
                   fis.close();
                   bos.close();
                   sock.close();
                   // display file transfert duration
                   System.out.println("Completed in :" + (end - start) + " ms !");
              } catch (IOException e) {
                   e.printStackTrace();
    DECODER :
    public class Decoder {
         private File destFile;
         public Decoder(String path){
              try {
                   // setting up destination file
                   this.destFile = new File(path);
                   // setting up file writting stream
                   FileOutputStream fos = new FileOutputStream(this.destFile);
                   // setting up connection server
                   ServerSocket serv = new ServerSocket(5698);
                   // accepting client connection request
                   Socket sock = serv.accept();
                   // setting up reading stream for the connection
                   BufferedInputStream bis = new BufferedInputStream(sock.getInputStream());
                   // setting up byte buffer
                   byte[] buffer = new byte[1024];
                   // first reading
                   int read = bis.read(buffer);
                   while (read != -1){
                        // writting buffer content into file
                        for (int i=0; i < read; i++){
                             fos.write(buffer);
                        // reading next bytes
                        read = bis.read(buffer);
                   //closing streams
                   fos.close();
                   bis.close();
              } catch (IOException e) {
                   e.printStackTrace();

  • I need a reliable (auto reconnect, no data loss, etc) TCP/CP Socket class

    I have been searching for a third party (free or pay) socket class that will do things that all of us programmers must do:
    reconnect when socket is disconnected
    reconnect and re-send data (so no data loss)
    and implementing all of these other features that we all require for "reliable" network communications over public networks.
    I would like to use this socket class on both my client and server applications. Does one exist somewhere? It certainly must. I want something that is tried and proven. free is great with open source but paying money is okay too. thanks !

    I am surprised at these responses. Using JMS or creating my own ARQ seems to not meet my requirement (lots of overhead in the case of JMS you usually need a middle "server" and the overhead is huge in high bandwidth situations -- lots of cpu and extra bandwidth -- and the ARQ is a nice idea but i really dont want to create anything myself)
    The fact is TCP/IP is unreliable over the internet. anyone who tries to use sockets over the internet recognizes this. It is not an issue of my application but the fact of the internet. the internet is designed with the assumption that the internet is unreliable (hence why the government created ARPA and the internet)
    so what if i loosened the requirement and said it was okay to lose some packets, but i just need something that knows the other side is alive and will reconnect/discnonect appropriately? doesnt this exist already? i mean every tcp/ip programmer is doing this and anyone who implements tcp/ip with the assumption that the "network is reliable" is going to be in big trouble. It doesnt need to be TCP, it can be a reliable UDP (i dont care what transport is used) but i just need something where i can take my existing code, drop in this new class instead of "Socket" and get my project done. it would be nice if it had features like reconnecting, dropping data if it is too old or if there are too many messages. i will be using it in high bandwidth applications (20-50mbps over the internet) and dont need 100% packet reliability, if we drop some packets due to a hiccup that is ok, but i do need it to be intelligent in reconnecting and such.

  • Gmail over IMAP: data loss?

    I keep running over my Web host's quotas with my email, so I thought I'd give Gmail-over-IMAP a shot despite my distaste for Gmail's main Web interface.
    In Mail.app I selected all 2100 messages in my Inbox and copied them over to Gmail. The operation completed without reported errors, but only 1300 messages made it over! Disturbed, I re-imported the original Inbox from a backup and copied it up to Gmail again, this time as a separate mailbox (label). Again, 1300 messages. As a control, I then copied that same re-imported mailbox up to my original account, and a few minutes later all 2100 messages were visible on the server. So it's not Mail.app.
    Two bad things seem to be going on here. The first, and less severe, is that Gmail is running filters on these copied/moved messages as though they were new incoming mail - so some got flagged as spam or moved to other folders. While not a data loss issue, it's still annoying and not what one would expect.
    The second is just pure data loss. Even after tallying all the filtered mail I came up about 500 messages short.
    I'd love to think I'm missing something obvious here and there's a way around (since the extra, free storage would be lovely and even a mediocre AJAX UI is better than SquirrelMail), but clearly I can't trust a service that predictably loses messages.
    Any thoughts?

    Well, I don't know how, but after removing all the accounts on my Pre (manually), manually backing up what remained to my Synergy/Palm Profile account, running WebOS Doctor once more and then re-adding all my accounts manually, Gmail is working again.  I can't say exactly what fixed it, but man, what a pain!
    Oh, and on a side note - nice going with the 2010 EAS (Exchange) calendar FAIL, Palm.  I really appreciate that "little" bug too. *Rant off*
    (http://forums.precentral.net/webos-synergy-synchronization/222080-calender-not-synching-new-year.htm...)
    Message Edited by dpellenwood on 01-02-2010 06:19 PM

  • Synchronizing peers in transfer over Socket

    Hi again!
    I'm relatively new to Java, so there are many issues I still have to figure out ;-)
    Here are two of them:
    1) How can peers be synchronized in transfer over Socket? For example:
    This is the receiving peer:
    DataInputStream dsin = new DataInputStream(socket.getInputStream());
    String s = dsin.readUTF();This is the sending peer:
    DataOutputStream dsout = new DataOutputStream(socket.getOutputStream());
    dsout.writeUTF("something...");
    dsout.close();At the receiving peer in some cases the EOFException or SocketException (Socket closed) are raised. I suspect this happens either because the receiver tries to read input before it is fully transfered or when the sender already managed to close the socket's OutputStream.
    So how can such a transfer be synchronized?
    2) What if both peers close their socket's OutputStream? Does this result in closing the connection and releasing all its resources, such as port?
    Thank you everyone!

    this is what I learnt:Sorry, try again!
    DO NOT close the Socket on any endpoint until you make sure that the other endpoint managed to call socket.getInputStream().This 'rule' is quite unnecessary.
    According to the documentation, getInputStream() may return a stream which buffer was discarded by network software if a broken connection was detected.That's a complete misreading and misquoting of the documentation. A reset can happen to the connection at any time; can cause loss of data from te socket receive buffer; and has nothing to do with the operation of getting the input stream. Getting the input stream of a socket has nothing to do with the network or the state of the connection. It just constructs a Java object. So this rule is quite pointless.
    Even more, it seems to be a good practice not to close the Socket until you are sure that the other endpoint will not try to read from the channel.You've got that back to front as well. THink about that some more and you will see it involves an infinite regression.
    The only rules you need are these:
    (a) don't close the socket until you're sure the other end has finished writing. You have to close the socket while the other end is still reading, so that it will get a EOS indication, so it will know you've gone away, so it will stop writing and close its end of the socket.
    (b) closing the socket or either of its streams closes the other two items. You should always close the topmost output stream of a socket and nothing else.

  • Send XML over Sockets

    I am beginning and I need to send XML formatted data from Swing Client to Server for parsing/processing/and response.
    There are no web server available to use. I think its best to use socket connection, but how do I send xml data over socket, and how do I receive it from server and parse it?
    I have read and cannot find a similar example.

    Xerces has DOMSerializer which can be used to serialize a Document object to a string. Once it's a string it's trivial to transmit over a socket connection. On the other side, to parse it, you'll have to create a StringReader for the received string and then an InputSource from the StringReader. You'll then be able to pass the InputSource to the DocumentBuilder.parse( ) method to generate a Document on the receiving side.
    Hope that helps,
    - Jesse

  • Creating Mime-messages from String data

    How do I save string data of email received from Outlook Express by calling BufferedReader's readLine() method over a socket a connection so that it can be converted into MimeMessage.

    Sorry but i didn't read your code snipppet so well.
    So you have a Vector v wicht contains the client part of the dialog.
    This is a typical conversation: ( you don't use EHLO or HELO handshake!? it's considered rude not to introduce yourself :) )
    EHLO CLIENTNAME
    250
    MAIL FROM:<[email protected]>
    250 MAIL FROM:<[email protected]> OK
    RCPT TO:<[email protected]>
    250 RCPT TO:<[email protected]> OK
    DATA
    354 Start mail input; end with <CRLF>.<CRLF>
    Message-ID: <24569170.1093420595394.JavaMail.cau@PTWPC019>
    From: [email protected]
    To: [email protected]
    Subject: something
    Mime-Version: 1.0
    Content-Type: multipart/mixed;
         boundary="----=_Part_0_17459938.1093420595224"
    ------=_Part_0_17459938.1093420595224
    Content-Type: text/plain; charset=US-ASCII
    Content-Transfer-Encoding: 7bit
    TEXT CONTENTS
    ------=_Part_0_17459938.1093420595224
    Content-Type: text/html; charset=US-ASCII
    Content-Transfer-Encoding: 7bit
    <b>HTML CONTENTS<b>
    ------=_Part_0_17459938.1093420595224--
    250 <412ADBC5000000B5> Mail accepted
    QUIT
    221 ontrob1.bmsg.nl QUIT
    The results in the vector from DATA to the ending dot . should be the part of your constructor string;
    Use this constructor
    MimeMessage mm = new MimeMessage(null,  ByteArrayInputStream( yourstring.getBytes() )  ) ;at this moment you can deconstruct the mime further.
    maybe this code will help:
    you should call the dumpPart method like this dumpPart( mm );
         Store store;
         Folder folder;
         static boolean verbose = false;
         static boolean debug = false;
         static boolean showStructure = true;
         private static void dumpPart(Part part) throws Exception {
              if (part instanceof Message)
                   dumpEnvelope((Message) part);
              /** //Dump input stream ..
              InputStream is = part.getInputStream();
              // If "is" is not already buffered, wrap a BufferedInputStream
              // around it.
              if (!(is instanceof BufferedInputStream))
                   is = new BufferedInputStream(is);
              int c;
              while ((c = is.read()) != -1)
                   System.err.write(c);
              pr("CONTENT-TYPE: " + part.getContentType());
              * Using isMimeType to determine the content type avoids
              * fetching the actual content data until we need it.
              if (part.isMimeType("text/plain")) {
                   pr("This is plain text");
                   pr("---------------------------");
                   if (!showStructure)
                        System.out.println((String) part.getContent());
              } else if (part.isMimeType("multipart/*")) {
                   pr("This is a Multipart");
                   pr("---------------------------");
                   Multipart mp = (Multipart) part.getContent();
                   level++;
                   int count = mp.getCount();
                   for (int i = 0; i < count; i++)
                        dumpPart(mp.getBodyPart(i));
                   level--;
              } else if (part.isMimeType("message/rfc822")) {
                   pr("This is a Nested Message");
                   pr("---------------------------");
                   level++;
                   dumpPart((Part) part.getContent());
                   level--;
              } else if (!showStructure) {
                   * If we actually want to see the data, and it?s not a
                   * MIME type we know, fetch it and check its Java type.
                   Object o = part.getContent();
                   if (o instanceof String) {
                        pr("This is a string");
                        pr("---------------------------");
                        System.out.println((String) o);
                   } else if (o instanceof InputStream) {
                        System.err.println("HELLO CAU 1111");
                        pr("This is just an input stream");
                        pr("---------------------------");
                        InputStream is2 = (InputStream) o;
                        int c2;
                        while ((c2= is2.read()) != -1)
                             System.out.write(c2);
                        System.err.println("\nHELLO CAU");
                   } else {
                        pr("This is an unknown type");
                        pr("---------------------------");
                        pr(o.toString());
              } else {
                   pr("This is an unknown type");
                   pr("---------------------------");
         private static void dumpEnvelope(Message msg) throws Exception {
              pr("This is the message envelope");
              pr("---------------------------");
              Address[] a;
              // FROM
              if ((a = msg.getFrom()) != null) {
                   for (int j = 0; j < a.length; j++)
                        pr("FROM: " + a[j].toString());
              //TO
              if ((a = msg.getRecipients(Message.RecipientType.TO)) != null) {
                   for (int j = 0; j < a.length; j++)
                        pr("TO: " + a[j].toString());
              // SUBJECT
              pr("SUBJECT: " + msg.getSubject());
              // DATE
              Date d = msg.getSentDate();
              pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN"));
              //FLAGS
              Flags flags = msg.getFlags();
              StringBuffer sb = new StringBuffer();
              Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags
              boolean first = true;
              for (int i = 0; i < sf.length; i++) {
                   String s;
                   Flags.Flag f = sf;
                   if (f == Flags.Flag.ANSWERED)
                        s = "\\Answered";
                   else if (f == Flags.Flag.DELETED)
                        s = "\\Deleted";
                   else if (f == Flags.Flag.DRAFT)
                        s = "\\Draft";
                   else if (f == Flags.Flag.FLAGGED)
                        s = "\\Flagged";
                   else if (f == Flags.Flag.RECENT)
                        s = "\\Recent";
                   else if (f == Flags.Flag.SEEN)
                        s = "\\Seen";
                   else
                        continue; // skip it
                   if (first)
                        first = false;
                   else
                        sb.append(' ');
                   sb.append(s);
              String[] uf = flags.getUserFlags(); // get user-flag strings
              for (int i = 0; i < uf.length; i++) {
                   if (first)
                        first = false;
                   else
                        sb.append(' ');
                   sb.append(uf[i]);
              pr("FLAGS: " + sb.toString());
              // X-MAILER
              String[] hdrs = msg.getHeader("X-Mailer");
              if (hdrs != null)
                   pr("X-Mailer: " + hdrs[0]);
              else
                   pr("X-Mailer NOT available");
         static String indentStr = " ";
         static int level = 0;
         * Print a, possibly indented, string.
         public static void pr(String s) {
              if (showStructure)
                   System.out.print(indentStr.substring(0, level * 2));
              System.out.println(s);
    Tricae

  • Urgently needed(data transfer on sockets)

    hello friends,
    I m in need of java code to read text and graphics(lines,circles etc.)from JTextPane and then to transfer this data on sockets to a client.
    IF anybody can help,I'll be highly thankful.I need it urgently.

    i did the follwing when i had a similar requirement...i used java.util.vectors and passed them over sockets to the other end. the advantage of doing this was that I inserted a string ('string_msg') if any text messages were sent or ('graph_pts') if Point objects of the circle or line was sent, as the first element of the vector and the next element was the text-object(StringBuffer) / object[](incase of Point objects) itself.
    here is the piece of code to send the vector...
    try {
                ucon = (new URL(serverURL, serverPathStr)).openConnection();
                ucon = setUcon(ucon);
                objectoutputstream = new ObjectOutputStream(new BufferedOutputStream(ucon.getOutputStream()));
                objectoutputstream.writeObject(obj);
                objectoutputstream.flush();
                objectinputstream = new ObjectInputStream(new BufferedInputStream(ucon.getInputStream()));
                obj1 = objectinputstream.readObject();
                objectinputstream.close();
                objectoutputstream.close();
            catch....in the case above, the server simply returns a string "OK_recd" which is recd as a sent confirmation via obj1.
    Note: the server &/ client should also use ObjectInput/Output Streams to recieve the object and type cast the object recd to Vector.
    the first element in the vector (used as a handshake) to identify the next element in the vector...
    hope this helps!

  • Problem with Sending files over Sockets

    Hi. I have a problem when I try to send files over sockets. When I send text files it works well but when I try to send .jpg or other kind of files it doesn't work well because some characters are wrong, I hope you can help me.
    Here is my code:
    //Sender code
    import java.io.*;
    import java.net.*;
    class Servidor{
         Servidor(){
              try{
                   String arch="art.jpg";
                   ServerSocket serv=new ServerSocket(125);
                   Socket socket=serv.accept();
                   System.out.println("Conectado");
                   int c;
                   BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                   FileInputStream fis=new FileInputStream(arch);
                   File f=new File(arch);
                   bw.write(""+f.length());
                   bw.newLine();
                   bw.flush();
                   System.out.println("Escribiendo");
                   while((c=fis.read())!=-1){
                        bw.write(c);
                   bw.flush();
                   fis.close();
                   System.out.println("Terminado");
                   while(true){
              }catch(Exception e){
                   System.out.println(e);
         public static void main(String arg[]){
              new Servidor();
    //Client code
    import java.io.*;
    import java.net.*;
    class Cliente{
         Cliente(){
              try{
                   Socket socket=new Socket("localhost",125);
                   System.out.println("Conectado");
                   BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
                   long tam=Long.parseLong(br.readLine());
                   long act=0;
                   FileOutputStream fos=new FileOutputStream("resp.jpg");
                   System.out.println("Recibiendo: "+tam);
                   while(act<tam){
                        fos.write(br.read());
                        act++;
                   System.out.println("Terminado: "+act+" / "+tam);
                   fos.close();
              }catch(Exception e){
                   System.out.println(e);
         public static void main(String arg[]){
              new Cliente();
    }

    I don't think you want BufferedReader and OutputStreamWriter, you want ByteArrayOutputStream and ByteArrayInputStream . The problem is that you are sending jpegs (binary data) as text.

  • Labview connect over sockets with php

    Hello, i´ve a simply led.
    I would control value of led over sockets using PHP programming language. My question is, where are documentation and examples? I found many examples between 2 or more Labview applications but not in PHP. I don´t found documentation that explins information to send to Labview application from PHP sockets...
    It´s possible? 
    Thanks!

    Hello, it work! I changed the number of bytes that TCP READ read. When string is equals "a", it set led to true:
    PHP Code:
             $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
            socket_bind($socket, "127.0.0.1");
            socket_connect($socket, "127.0.0.1", 4005);
            if(strcmp($data,"")==0){
                $msg = "Default msg";
            } else {
                $msg = $data;
            $size = strlen($msg);
            $sock_data = socket_write($socket, $msg, strlen($msg));
            $res = "Data sended ($size) with response $sock_data.";
    But now, a get this error when TCP close:
    But i don´t understand because i´ve defined my IP in VI Server:Machine Access .
    Any idea?

  • [DATA LOSS] I closed the Tab Groups and all my tabs dissapeared. How can I recover the tabs in Firefox 26? Would you please just delete this feature?

    Thank-you in advance for reading all of this.
    A slip of the mouse in trying to return to the left-most tab caused the tab groups feature to take over the window. I completely failed to comprehend what I was looking at and closed the thing by clicking the x because I damn sure didn't want what I was looking at. Undo close group? Of course not, I didn't want a group in the first place. Hey! My tabs are completely gone now! So in just a few steps all of which seemed innocent, I have lost all but ten of the tabs that were open, and those were only the most recent ten (and actually older tabs would have been more valueable than newer so insult on top of injury).
    I don't think increasing the number of undoable tab closures is the answer. I think getting rid of the tab groups feature all together is the best way to go. I seem to have lost all the tabs I had open, irretrievably, and some of them had been open for WEEKS so they can't be reopened from history.
    The tab groups feature is a data loss bug. Please remove it from the UX completely. If you have to figure out a way to grandfather people who actually have a tab group, fine but don't further vex me with it, please.
    The reason this catastrophe has occurred is that your feature, was so discoverable that I activated it by mistake, and the UI after that had to be learned on the spot, yet was too complicated to learn. You really should withdraw it until you can figure out how to keep the UI for it from causing data loss such as I have experienced this morning.
    Also, there may be other questions on this feature which are from a certain point of view the same as this one. It's hard for me to tell for sure. None of them had a true resolution so that's why I posted this one, also I'm seeking a specific fix, removal of the offending feature.
    Why remove the feature? Because if I allow in my discussion the possibility of retaining it, it will stick around in its present and dangerous form until your team is done bikeshedding the new form it should take. Instead I want you to delete the feature and then require its champion to convince you that a new incarnation won't cause data loss before you allow it back in.
    Fellow users, if you know of a way to recover all 50 lost tabs from an "undo close tab group incident", I would be grateful for that advice, but I would still believe the feature should be deleted. Some of the tabs have been retained for months so digging them out of the history is not practical.

    I am not 100% certain but I am fairly sure development of this tab feature has ceased and it is likely to be deprecated. I am even less sure what the replacement will be.
    Thus forum is not the place for discussing development issues or feature requests. (Developers do not use this site)
    *You could comment using feedback <br /> https://input.mozilla.org/en-US/feedback
    *Or try to find a developers forum or mailing list <br /> http://www.mozilla.org/about/forums/#general-development
    I have not tried this and am not even using Windows at present but the tabs groups are stored as entries in the sessionstore.js files. Firefox has such a file plus sometimes numbered copies and a backup copy. Firefox will have re-writen these files but I suppose there is a posibility the Windows OS may have kept copies.
    * see http://windows.microsoft.com/en-US/windows7/Previous-versions-of-files-frequently-asked-questions
    * http://kb.mozillazine.org/Sessionstore.js Note the files are kept within the Firefox Profile
    ** Firefox Button -> Help -> Troubleshooting [open profile] (or some thing similar) is one method of locating the profile.
    Find and backup any current sessionstore.js file. Consider also bookmark or otherwise recording anything you have open. Now find any previous versions and try putting them in Firefox's profile before restarting it.

  • Data loss Lacie 500GB external drive_ disk utility changed partition!

    Details of problem. I have a 500GB Lacie mini hub HDD which is used with an iMac angle poise. Recently it has been playing up- unable to access folders/files etc. and since I know the PSU fails on these items (capacitors fail -5V and 12V go haywire- already fixed another one - I have a 320GB with a mac mini setup) I removed unit from the imac and connected in place of the 320GB lacie on the mac mini, using the known good PSU. The iMac is running latest 10.4 and mac mini is running latest snow leopard 10.6.1
    The Lacie spun up and mounted OK and I was able to access all files folders with no issue, so since I was keen to make sure it was 'fixed' I ran disk utility. It ran and said it verified and then I realised I hadn't run repair so re-did this. Big mistake!
    It did the same run and said no problems found, but it then said something like updating partition! Horrified I waited and it seemed to finish or had finished straight away. Not sure. I looked at folders and yes main 2 items in place, but nothing showing below this. ****. It got worse. I ejected and tried to reconnect and low and behold it says drive needs formatting now. Disk utility even shows this 500GB as having 2.2TB of space, which I see in other posts is another issue.
    I have important data backed up elsewhere, but there are a large number of files I do not have copies of and suspect there is a way to recover these. I have since seen all the 'data loss' guest account issues and wonder if this is yet another bug in snow leopard.
    Have tried running Techtool Pro 5.0.6 to see if it can see the data but its not seeing anything. Will try Diskwarrior and others, but may well shelve to see if apple gets an os update released for data loss issues.
    Any thoughts on how to recover? Anyone with a similar issue? I am pretty certain this is not a failed hard drive as it sounds 100% normal. Thanks for any help or guidance.

    Thanks for all the comments recieved. V.K. made me re-evaluate what I had proved or not. I was fairly certain (not 100%) that the drive mech was OK, because the psu had failed, but should have proved drive mech was actually OK. So I removed the mech (as USB abd firewire can't do SMART etc.) and hooked up to an old G4 Powermac. I then found that the SMART verified, but had forgotten the 128GB limitation on older macs. So removed and got a PC to hook it up and run latest IBM_Hitachi drive fitness and other diags. (its a Deskstar HD and I have had almost zero issue with these drives over the years.) It checks out fine, so I was correct in my initial thoughts, only the PSU was faulty.
    So back to my initial suspicions that Snow Leopard or disk utility has screwed things up, maybe a bug, maybe not. And I did run verify first and it said it was OK, only when I re-ran the repair did it then do a "partition update" (or whatever it said - should have done a screen capture - searched apple but can't find listing of all mesgs avail. must be in developers site I expect). So I am back at looking at how to recover, if at all possible, but as Alsoft have said this is not something Diskwarrior can do directly. Files must still be there just partiton map is now in a ... needs to be initialised mode. Not that I will do that.
    So I guess summary is possible bug/funny in 10.6 and/or disk utility.
    sounds like I will be contacting Alsoft now
    may read up on partition map damage first, so I get a better picture of whats involved.
    Cheers and thanks for all the help/ideas.
    BTW - been using macs_pcs for decades now and helping friends & family fix things as and when. This is first time needed to post on forum as always found answers to questions I had previously. Must remember the old adage of not jumping onto new technology until it has bedded down I bet if I had hooked up to the old G4 Powermac I wouldn't be in this position. Thanks again.

  • Xy graph in GUI. Show string data related to a X,Y point

    It is possible to show string data, while hovering the mouse or clicking a cursor, attached/related to a X,Y point in a XY graph??
    Kind regards

    I assume you want to let the x-y-value pair hover over the graph at mouse position.Perhaps this will help you:
    http://forums.ni.com/t5/LabVIEW/Text-overlay-annotation-onto-an-intensity-graph/m-p/883438/highlight...
    Another option might be just to use the cursor functionalities of XY graphs, although they don't hover at mouse position.
    Other than that I had a similar request on Image Displays with IMAQ (Vision Development Module) where it turned out that using a simple string control from the classic palette that you move around according to mouse position is an efficient way to let information hover wherever you want. Check it out:
    http://forums.ni.com/t5/LabVIEW/Why-do-overlays-take-so-much-longer-on-single-precision/m-p/2376338#...

Maybe you are looking for

  • FIFO Underruns in newer versions of Linux using the Ivy Bridge cpus

    I have been getting consistent results from my Lenovo Z580 where an error will apear when upgrading to a newer version of linux past 3.15.8. More specifically a "[drm:cpt_serr_int_handler] *ERROR* PCH transcoder A FIFO underrun".  This also includes

  • Difference forecast results between the Batch run and interactive run in DP

    Hi Guru's, I am running the forecast in DP with interactive and batch run (with same selection id and same univariate profile) but  i am getting the difference results not both are equal??? Is it we will not get the same results?? If i tried with onl

  • How to set the precedence of conflicting contact photos

    I have two accounts in my contacts app, one for iCloud (my personal contacts) and one from my employer's CardDav server. My problem is that some of my work colleages are also personal friends, with contact records in my iCloud account-and I myself ha

  • Oracle Telesales-Party creation

    Hi, In telesales, We have to create Party first and Party will be converted into customer. I am facing one issue here that the application is creating the Account number directly. How to stop this. What is the profile set up for this Regards R

  • Unwanted automatic date calculation

    I have an entity object that has a date type of field in it. I have created a view object and an application module based on it. when i test the application module, if i put a date such as 2000-10-61 (default format of yyyy-mm-dd), then instead of gi