2,安装
3,启动一个cmd窗口,敲入javac 如果显示不是命令的话,把环境变量配置一下。
计算机⇒属性⇒系统保护⇒高级⇒环境变量⇒系统变量⇒path
假如的你的jdk安装目录为E:\jdk就把E:\jdk\bin这个地址复制到path里面去,注意后面加个分号()
4,再次运行javac 会显示一些内容,恭喜你搭建好了。
以下是Sun提供的一个简单的“Knock Knock"”服务器:import java.net.*import java.io.*public class KnockKnockServer {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null
try {
serverSocket = new ServerSocket(4444)
} catch (IOException e) {
System.err.println("Could not listen on port: 4444.")
System.exit(1)
}
Socket clientSocket = null
try {
clientSocket = serverSocket.accept()
} catch (IOException e) {
System.err.println("Accept failed.")
System.exit(1)
}
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true)
BufferedReader in = new BufferedReader(
new InputStreamReader(
clientSocket.getInputStream()))
String inputLine, outputLine
KnockKnockProtocol kkp = new KnockKnockProtocol()
outputLine = kkp.processInput(null)
out.println(outputLine)
while ((inputLine = in.readLine()) != null) {
outputLine = kkp.processInput(inputLine)
out.println(outputLine)
if (outputLine.equals("Bye."))
break
}
out.close()
in.close()
clientSocket.close()
serverSocket.close()
}}
再简单不过了。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)