package SetTcpNoDelayTest;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class ServerSocketFrame extends JFrame {
private JTextArea ta_info;
private JScrollPane scroll;
private ServerSocket server;
private Socket socket;
public ServerSocketFrame(){
ta_info=new JTextArea(8,20);
scroll=new JScrollPane(ta_info);
add(scroll);
getServer();
pack();
}
public void getServer(){
new Thread(){
public void run(){
try {
server=new ServerSocket(1982);
ta_info.append("服务器套接字创建成功!\n");
while(true){
ta_info.append("等待链接……\n");
ta_info.append("连接后关闭socket缓存……\n");
socket=server.accept();
//关闭socket缓存
socket.setTcpNoDelay(true);
ta_info.append("socket缓存已关闭\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
}