0

したがって、基本的に私は自分のコンピューター広告で2つのJavaアプリケーションを実行しており、データを送信した後、Java tcpを介した送信速度を計算し、速度は常に約7メガビット/秒ですとにかく少なくとも56メガビット/秒を期待していましたクライアントアプリケーションです:

 import java.io.*;
import java.net.*;

class TCPClient
{
 public static void main(String argv[]) throws Exception
 {


 System.out.println("Hello, World");


           String modifiedSentence;
           BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
           Socket clientSocket = new Socket("127.0.0.1", 7);

           BufferedInputStream inFromServer  = new BufferedInputStream(clientSocket.getInputStream());

           double count=0;
           OutputStream socketOutputStream = clientSocket.getOutputStream();

        String s = "012345678901234567\n";    

        byte[] bytes = s.getBytes(); 

        final int BUFFER_SIZE = 65536;
        byte[] buffer = new byte[BUFFER_SIZE];

        // socketOutputStream.write(bytes);
        // inFromServer.read(buffer);
        // modifiedSentence = new String(buffer);
        // System.out.println("FROM SERVER:" + modifiedSentence);
         socketOutputStream.write(bytes);
         long times=System.nanoTime() ;
        long temp=times;long temp2=times;
           while (true) {
               socketOutputStream.write(bytes);
           count++;

           socketOutputStream.flush();
               if(count>=100000){
                   break;

               }

           }

           times=System.nanoTime() ;
           System.out.println("time(ns) : " + (times-temp2));
           double speed=(72*2*count)/(double)((times-temp2)*Math.pow(10,-9));
           System.out.println("speed : " + speed/(1024*1024));
           clientSocket.close();


 }
}

サーバーコードは次のとおりです。

import java.io.*;
import java.net.*;

class TCPClient extends Thread
{
    Socket clientSocket;
      public TCPClient(Socket socket) {
            super("KKMultiServerThread");
            this.clientSocket = socket;
            }

 public  void run() //throws Exception
 {


 System.out.println("Hello, World");
    try {

           String modifiedSentence;


           BufferedOutputStream outToServer = new BufferedOutputStream(clientSocket.getOutputStream());
           BufferedInputStream inFromServer  = new BufferedInputStream(clientSocket.getInputStream());

           double count=0;


        String s = "012345678901234567\n";    

        byte[] bytes = s.getBytes(); 
        long times=System.nanoTime() ;
        long temp=times;long temp2=times;
        final int BUFFER_SIZE = 19;
        byte[] buffer = new byte[BUFFER_SIZE];

         modifiedSentence = "";
           while ((inFromServer.read(buffer))!=-1) {

          // outToServer.write(bytes);
         //  outToServer.flush();


           }

           System.out.println("FROM SERVER:" + modifiedSentence);

           clientSocket.close();

     } catch (UnknownHostException e) {
         System.err.println("Don't know about host: taranis.");
         System.exit(1);
     } catch (IOException e) {
         System.err.println("Couldn't get I/O for "
                            + "the connection to: taranis.");
         System.exit(1);
     }


 }


}

サーバーコードは書き込みではなく受信のみに調整され、クライアントは送信のみに調整され、スループットは27Mbit /秒に増加しましたが、イーサネットの半分の速度である50Mbit /秒には増加しませんでした。

4

1 に答える 1