基本信息
源码名称:vpn实现代码(Android)
源码大小:0.01M
文件格式:.rar
开发语言:Java
更新时间:2016-01-22
   源码介绍


package vpn;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;

class Client {
	public static void startClient(String sharedKey) throws Exception {
		Scanner input = new Scanner(System.in);

        String host;
        System.out.println("Server IP to connect to:");
		host = input.next();
		
        Socket clientSocket = new Socket(host, 6789);
        aes AES = new aes(sharedKey);
        
        ObjectInputStream in = new ObjectInputStream(clientSocket.getInputStream());
        ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream());
        
        if (MutualAuthentication.muAuth(TwoWayVPN.CLIENT, out, in, AES)) {
        	while(true){
        		System.out.println("Data to send: (enter exit to quit)");
        		String send = input.next();
        		
        		if (send.equals("exit")) {
            		String encryptSend = AES.encrypt(send);
            		out.writeObject(encryptSend);
        			System.out.println("Client closing");
        			break;
        		}
        	
        		String encryptSend = AES.encrypt(send);
        		out.writeObject(encryptSend);
        		System.out.println("To Server>"   send);
        	}
        }
        input.close();
        in.close();
        out.close();
        clientSocket.close();
	}
}