3
我想了解如何使用Java在Java中創建一個TCP服務器。但我沒有得到我真正需要的東西。我是否必須將密鑰文件導入到java中,而我呢,怎麼做呢?或者我只需要將Socket的類型從Socket更改爲SSLSocket?我讀過一些文章,但找不到有用的東西,因爲他們都只是採取http進行溝通。我需要它爲我自己的協議。在我的情況下,這將是一個這樣的程序:如何用java做一個SSL tcp服務器?
int port = 4444;
ServerSocket serverSocket = new ServerSocket(port);
System.err.println("Started server on port " + port);
// repeatedly wait for connections, and process
while (true) {
// a "blocking" call which waits until a connection is requested
Socket clientSocket = serverSocket.accept();
System.err.println("Accepted connection from client");
// open up IO streams
In in = new In (clientSocket);
Out out = new Out(clientSocket);
// waits for data and reads it in until connection dies
// readLine() blocks until the server receives a new line from client
String s;
while ((s = in.readLine()) != null) {
out.println(s);
}
// close IO streams, then socket
System.err.println("Closing connection with client");
out.close();
in.close();
clientSocket.close();
}
使用SSL連接。那麼如何做到這一點?
感謝, 托馬斯