forked from LupusNobilis/java-org.hwo
Kleine Änderungen
parent
a6cac2bff9
commit
7ac9268057
|
@ -54,9 +54,11 @@ public class InteractiveObjectHelper {
|
|||
|
||||
public static void showEditor(Object o)
|
||||
{
|
||||
if (o != null){
|
||||
IInteractiveObjectEditor editor = getEditor(o);
|
||||
editor.setInteractiveObject(o);
|
||||
editor.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,25 +12,60 @@ import java.net.InetAddress;
|
|||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleRPCServer extends Thread{
|
||||
|
||||
class ClientConnection extends Thread {
|
||||
private Socket socket;
|
||||
|
||||
public ClientConnection(Socket socket){
|
||||
this.socket = socket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
addClientConnection(this);
|
||||
handleOneRequest(socket);
|
||||
removeClientConnection(this);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<ClientConnection> clientConnections;
|
||||
private Hashtable<String, Object> registeredObjects;
|
||||
private ServerSocket serverSocket;
|
||||
|
||||
private boolean exit;
|
||||
|
||||
public SimpleRPCServer(InetAddress listenAddress,int port) throws IOException
|
||||
{
|
||||
this.registeredObjects = new Hashtable<String, Object>();
|
||||
this.serverSocket = new ServerSocket(port, 5, listenAddress);
|
||||
this.clientConnections = new LinkedList<SimpleRPCServer.ClientConnection>();
|
||||
}
|
||||
|
||||
synchronized void addClientConnection(ClientConnection clientConnection){
|
||||
this.clientConnections.add(clientConnection);
|
||||
}
|
||||
|
||||
synchronized void removeClientConnection(ClientConnection clientConnection){
|
||||
this.clientConnections.remove(clientConnection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!exit){
|
||||
try {
|
||||
handleOneRequest();
|
||||
Socket socket = serverSocket.accept();
|
||||
if (socket != null){
|
||||
ClientConnection client = new ClientConnection(socket);
|
||||
client.start();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -47,9 +82,7 @@ public class SimpleRPCServer extends Thread{
|
|||
}
|
||||
}
|
||||
|
||||
public void handleOneRequest() throws IOException{
|
||||
Socket socket = serverSocket.accept();
|
||||
|
||||
public void handleOneRequest(Socket socket) throws IOException{
|
||||
DataInputStream dis = new DataInputStream(socket.getInputStream());
|
||||
int len = dis.readInt();
|
||||
byte[] request = new byte[ len ];
|
||||
|
@ -106,7 +139,6 @@ public class SimpleRPCServer extends Thread{
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue