📄 simpleserver.java
字号:
package net;
import java.net.*;
import java.io.*;
public class SimpleServer {
public static void main(String args[]) {
ServerSocket s = null;
// Register your service on port 5432
try {
s = new ServerSocket(5432);
} catch (IOException e) {
e.printStackTrace();
}
// Run the listen/accept loop forever
while (true) {
try {
// Wait here and listen for a connection
System.out.println("Simple Server Wait...");
Socket s1 = s.accept();
// Get output stream associated with the socket
OutputStream s1out = s1.getOutputStream();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s1out));
// Send your string!
bw.write("Hello Net World!\n");
// Close the connection, but not the server socket
bw.close();
s1.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -