0
클라이언트가 서버에 개체를 보내도록 관리했지만 서버가 개체를 보낸 클라이언트에게만 올바르게 회신하지만 서버 측에서 포트를 전달하고 서버에서 포트 연결을 허용해야했습니다 측면, 지금은 특정 클라이언트에게 회신/메시지를 보낼 수없는 항상 연결을 거부 할 수없는 것 portforwardind/클라이언트 측 방화벽에서 중재는 누군가가 채팅을 사용할 수 있어야하므로 가능하지 않습니다 (클라이언트 클라이언트가되어 서버가되지 않아야 함). 어떤 아이디어가이 작품을 만드는 방법? http 터널링 또는 rmi 프록시에 대해 들었지만 코드 단위로 어떻게 작동합니까?RMI가 인터넷을 통해 채팅
public class Main {
public static void main(String [] args) {
String input;
Scanner in = new Scanner(System.in);
input = in.nextLine();
try
{
Message b =(Message) Naming.lookup("//xx.xx.xx.xx:1099/Message");
Client c=new Client(input);
UnicastRemoteObject.exportObject(c, 1100);
b.addUser(c);
while(true)
{
input = in.nextLine();
if(input.contentEquals("deconnection"))
{
b.exit();
break;
}
else if(input.startsWith(">"))
{
b.broadcast(c,"test");
}
}
in.close();
}
catch (NotBoundException re) { System.out.println(re) ; }
catch (RemoteException re) { System.out.println(re) ; }
catch (MalformedURLException e) { System.out.println(e) ; }
}
}
서버 측 : 다음 clientlist가 발견 된 MessageImpl.java와
public class Serveur
{
public static void main(String [] args) {
try {
MessageImpl objLocal = new MessageImpl();
Naming.rebind("rmi://localhost:"+1099+"/Message" , UnicastRemoteObject.exportObject(objLocal, 1100)) ;
System.out.println("Serveur pret");
}
catch (RemoteException re) { System.out.println(re) ; }
catch (MalformedURLException e) { System.out.println(e) ; }
}
}
:
public class MessageImpl
implements Message {
public Vector<ClientInterface> clientlist;
public MessageImpl() throws RemoteException {super();listec=new Vector<ClientInterface>();};
public String envoiMessage() throws RemoteException {
return("message test");
}
public boolean isNew(ClientInterface c) throws RemoteException
{
return false;
}
public String test() throws RemoteException
{
System.out.println("re");
return "test";
}
public void addUser(ClientInterface c) throws RemoteException
{
test();
clientlist.add(c);
}
public void broadcast(ClientInterface c,String message) throws RemoteException
{
int i;
for(i=0;i<clientlist.size();i++)
{
if(clientlist.elementAt(i).getUsername().equals(c.getUsername()))
{}
else
{
clientlist.elementAt(i).getMessage(c.getUsername()+" : "+message);
}
}
}
public String exit() throws RemoteException
{
try{
return "exiting messenger";
}
catch(Exception e){return "erreur deconnection";}
}
}
어떻게 폴링을 사용할 수 있습니까? 클라이언트가 묻는 질문에 관계없이 서버에서 클라이언트로의 연결을 거부해야합니까? – user3552079
클라이언트가 연결을 요구하지 않습니다. 서버가 연결을 요구합니다. – EJP
아 그래, 어떻게 할 수 있니? 좀 모범을 보여 주시겠습니까? – user3552079