如果您想要比 RMI 和 JMS 更简单的东西,您可以使用套接字进行进程间通信。
关于套接字的 java 教程可能是一个不错的起点。
一个简单的单消息客户端-服务器,服务器等待客户端加入,然后从客户端接收消息,如下所示:
public class SocketsServer {
public static void main(String[]rags) throws Exception
{
ServerSocket ss1 = new ServerSocket();
ss1.bind(new InetSocketAddress("localhost",9992));
//accept blocks until someone connects
Socket s1 = ss1.accept();
BufferedReader br = new BufferedReader(new InputStreamReader(s1.getInputStream()));
String line;
while( (line = br.readLine()) != null )
{
System.out.println(line);
}
s1.close();
ss1.close();
}
}
对于客户端:
public class SocketsClient {
public static void main(String[]args) throws Exception
{
Socket ss = new Socket();
ss.connect(new InetSocketAddress("localhost", 9992));
PrintWriter pw = new PrintWriter(ss.getOutputStream(), true);
pw.println("hello socket");
ss.close();
}
}