?? tcpclient.java
字號:
/**
* This class models a client using TCP to communite with the server.
*
* @author tyrant
* @version 1.0.0
*/
import java.net.*;
import java.io.*;
public class TCPClient {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
long totalTime = 0;
long startTime = 0;
long endTime = 0;
int counterOfPacket = 1;
/* byte arrays to store one byte to receive and to send. */
byte[] sendByte = new byte[1];
byte[] receiveByte = new byte[1];
sendByte[0] = 'a';
// get the start time before the while circle.
startTime = System.currentTimeMillis();
while (counterOfPacket <= 1000) {
// connect to the server.
Socket clientSocket = new Socket("localhost", 6000);
// iostreams to communicate with the server.
DataOutputStream outToServer = new DataOutputStream(
clientSocket.getOutputStream());
DataInputStream inFromServer = new DataInputStream(
clientSocket.getInputStream());
// exchange one byte with the server.
outToServer.write(sendByte, 0, sendByte.length);
inFromServer.read(receiveByte, 0, receiveByte.length);
counterOfPacket++;
clientSocket.close();
}
// get the end time after the while circle.
endTime = System.currentTimeMillis();
totalTime = endTime - startTime;
System.out.println("Total time: " + totalTime + "ms");
System.out.println("RTT: " + totalTime / 1000.0 + "ms");
} catch (Exception e) {
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -