📄 jbdorderserver.java
字号:
import java.io.*;
import java.net.*;
public class JBDOrderServer
{
protected final static String CLIENT_ID = "JBDOrderClient";
protected final static double CLIENT_VERSION = 1.0;
protected final static String SERVER_ID = "JBDOrderServer";
protected final static double SERVER_VERSION = 1.0;
protected final static String HOST = "localhost";
protected final static int PORT = 5670;
private boolean terminated = false;
private PrintWriter out;
public JBDOrderServer()
{
try
{
out = new PrintWriter(new FileWriter("JBDOrder.dat", true));
}
catch (IOException ioe)
{
System.err.println("Error opening data output file(s)");
}
start();
}
public void start()
{
try
{
ServerSocket server = new ServerSocket(PORT);
System.out.println(SERVER_ID + " " + SERVER_VERSION + " ready ...");
while (!terminated)
{
Socket connection = server.accept();
JBDOrderServerThread handler =
new JBDOrderServerThread(this, connection);
}
System.out.println(SERVER_ID + " shutting down.");
server.close();
}
catch (IOException ioe)
{
System.err.println("Error establishing server and streams");
}
finally
{
out.close();
}
}
public synchronized void writeOrder(CatalogOrder order)
{
out.println(order.exportData());
out.flush();
}
public static void main(String args[])
{
JBDOrderServer server = new JBDOrderServer();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -