title: The speed of socket is 120MB/s on a computer, is it normal?
body: <p>I tested the performance of transferring data from a program to another over socket on a single computer, and the speed is <strong>120MBytes/s</strong>, is it normal?</p>
  
  <p>My server and client programs are both extremely simple.</p>
  
  <p>And my computer is AMD Athlon X2 4000+, 4G DDR2 667 ram, with windows xp sp3.</p>
  
  <p>My friend said it was slow, and should be faster. But I don't know how can I improve them, or is there any other libraries I can try to get a better speed?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The server and client programs were both on my own computer, <strong>a single computer</strong>. The <strong>network card</strong> will limit the speed or not?</p>
  
  <hr>
  
  <p>Server.java</p>
  
  <pre><code>import java.io.OutputStream;
  import java.net.ServerSocket;
  import java.net.Socket;
  
  public class SimpleServer {
      public static void main(String[] args) throws Exception {
          ServerSocket server = new ServerSocket(6666);
          Socket socket = server.accept();
          OutputStream output = socket.getOutputStream();
  
          byte[] bytes = new byte[10 * 1024]; // 10K
          for (int i = 0; i &lt; bytes.length; i++) { bytes[i] = 12; } // fill the bytes
  
          // send them again and again
          while (true) {
              output.write(bytes);
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Client.java</p>
  
  <pre><code>public class SimpleClient {
  
      public static void main(String[] args) throws Exception {
          Socket socket = new Socket("127.0.0.1", 6666);
          InputStream input = socket.getInputStream();
          long total = 0;
          long start = System.currentTimeMillis();
  
          byte[] bytes = new byte[10240]; // 10K
  
          // read the data again and again
          while (true) {
              int read = input.read(bytes);
              total += read;
              long cost = System.currentTimeMillis() - start;
              if (cost &gt; 0 &amp;&amp; System.currentTimeMillis() % 1000 == 0) {
                   System.out.println("Read " + total + " bytes, speed: " + (total / (1024.0*1024)) / (cost / 1000.0) + " MB/s");
              }
          }
      }
  
  }
  </code></pre>