Chào các bác,
mình có viết cái socket gửi file từ server xuống client, và client gửi byte [] đến server, nhưng không hiểu tại sao khi chạy cùng lúc file và byte [] thì không được [IMG]images/smilies/21.gif[/IMG]
server:
Mã:
public static void main(String[] args) throws IOException, ClassNotFoundException {
if (!areKeysPresent()) {
generateKey();
}
ServerSocket serverSocket = new ServerSocket(15124);
ServerSocket serverSocket1 = new ServerSocket(15123);
Socket sock = serverSocket.accept();
Socket sock1 = serverSocket1.accept();
sendFile(sock);
byte [] cipherText = recvByte(sock1);
//ObjectInputStream inputStream = null;
////inputStream = new ObjectInputStream(new FileInputStream(PRIVATE_KEY_FILE));
//final PrivateKey privateKey = (PrivateKey) inputStream.readObject();
//final String plainText = decrypt(cipherText, privateKey);
System.out.println(cipherText);
sock.close();
sock1.close();
}
client
Mã:
public static void main(String[] args) throws IOException, ClassNotFoundException {
Socket sock = new Socket("127.0.0.1",15124);
Socket sock1 = new Socket("127.0.0.1",15123);
recvFile(sock);
String str = "hello world";
//ObjectInputStream inputStream = null;
//inputStream = new ObjectInputStream(new FileInputStream(PUBLIC_KEY_FILE));
//final PublicKey publicKey = (PublicKey) inputStream.readObject();
//final byte[] cipherText = encrypt(str, publicKey);
byte [] m = str.getBytes();
sendByte(sock1, m);
sock.close();
sock1.close();
}
các hàm sendFile, recvfile, sendByte, recvByte mình đã kiểm tra từng cái cho chạy ok .
View more random threads:
Ngọc Bích xanh bản chất thuộc dòng đá đá hoa (jade). Và cẩm thạch là tên gọi chung của ngọc bích. Vì thực chất chúng thuộc dòng đá đa khoáng được hình thành từ chất Silicat dưới dạng dioxy. Ngọc bích...
Chia sẻ Vòng tay ngọc bích xanh là...