“如何制作我的Java”;“研究框架”;是否为internet上的所有客户端计算机提供服务器程序(使用我的iMac)?
“如何制作我的Java”;“研究框架”;是否为internet上的所有客户端计算机提供服务器程序(使用我的iMac)?,java,macos,server,client-server,web-hosting,Java,Macos,Server,Client Server,Web Hosting,我已经构建了这个服务器客户端程序,在该程序中,客户端在他/她的窗格上绘制,并将更改复制到其他客户端studyFrame上 基本上,我想在真实的互联网(而不是本地网络)上测试我的客户机服务器程序,这样我和我的朋友(在另一个城市)就可以使用这个客户机服务器程序了。 我希望我的Java服务器程序可以在internet上使用,我相信有两种方法,一种是将iMac转换为web服务器,另一种是使用web托管服务 iMac mac OS Sierra已经删除了个人网络主机,因此我无法打开它,这里讨论的Stack
- 我已经构建了这个服务器客户端程序,在该程序中,客户端在他/她的窗格上绘制,并将更改复制到其他客户端studyFrame上
- 基本上,我想在真实的互联网(而不是本地网络)上测试我的客户机服务器程序,这样我和我的朋友(在另一个城市)就可以使用这个客户机服务器程序了。
- 我希望我的Java服务器程序可以在internet上使用,我相信有两种方法,一种是将iMac转换为web服务器,另一种是使用web托管服务
- iMac mac OS Sierra已经删除了个人网络主机,因此我无法打开它,这里讨论的StackOverflow上的所有文章都是旧的,因此这些解决方案不适用于我的mac
public Handler(Socket socket,int id) {
this.socket = socket;
try{ socket.setTcpNoDelay(true);}catch(Exception l) { }
ID=id;
//input=new Object[1000];
try{
if(out==null)
{
// System.out.println("trying to open output streams");
out = new ObjectOutputStream(socket.getOutputStream());
//System.out.println("ADDED WRITER....."+"setting requester no="+(frame.w_count+1));
w_count++; writers[w_count]=out;out.flush();writers[w_count].flush(); requester=w_count; count++;
}
if(in==null){
//System.out.println("trying to open input streams");
in = new ObjectInputStream(socket.getInputStream());}
// System.out.println("opened input stream successfully");
}catch(Exception k) { System.out.println(k.toString());}
}
public void server_out(Object[] inp)
{
try{
int o=0;
Object[] inpClone=Arrays.copyOf(inp,store);
int str=store;
store=0;
for (int u=0;u<(w_count+1);u++) {
//System.out.println("sending object to client");
//System.out.println("THIS.ID="+this.ID+" and w_count is ="+w_count);
if(u!=updateFrom) {writers[u].writeObject(inpClone);
writers[u].flush();}
//System.out.println("object sent to client"+u);
}
}catch(Exception k) {System.out.println(k.toString()); }
}
public void run() {
try {
while(true)
{
//System.out.println("RUNNING FROM CLIENT "+requester);
int o=0;
synchronized(writers)
{
synchronized(in)
{
//System.out.println("No client update pending");
String handOver="#dataHandOver";
// System.out.println("Asking Client No. "+requester+" for hand over..");
writers[requester].writeObject(handOver);
// System.out.println("Trying to read objects from Client No. "+requester);
Object test=in.readObject();
if(test!=null)
{
Object rec[]=(Object[])test;
input=rec;
//System.out.println("creating array upto="+c);
//store=c;
store=rec.length;
updateFrom=requester;
server_out(input);
}
// System.out.println("data dumped");
//}
//else in.readObject();
writers[requester].flush();
}
}
}
} catch (Exception e) {
System.out.println(e);
} finally {
System.out.println("came to finally");
if (out != null) {
//writers.remove(out);
}
try {
socket.close(); System.exit(0);
} catch (IOException e) {
}
}
}
}
}
公共处理程序(套接字,int-id){
this.socket=socket;
请尝试{socket.setTcpNoDelay(true);}catch(异常l){}
ID=ID;
//输入=新对象[1000];
试一试{
if(out==null)
{
//System.out.println(“试图打开输出流”);
out=newObjectOutputStream(socket.getOutputStream());
//System.out.println(“添加了写入程序…”“+”设置请求程序编号=“+(frame.w_count+1));
w_count++;writers[w_count]=out;out.flush();writers[w_count].flush();requester=w_count;count++;
}
if(in==null){
//System.out.println(“尝试打开输入流”);
in=newObjectInputStream(socket.getInputStream());}
//System.out.println(“已成功打开输入流”);
}catch(异常k){System.out.println(k.toString());}
}
public void server_out(对象[]inp)
{
试一试{
INTO=0;
对象[]inpClone=Arrays.copyOf(inp,store);
int str=存储;
存储=0;
对于(int u=0;uThis)这里的答案是相关的,应该让您开始。感谢您的输入,但我应该如何使用动态DNS服务。我有这个免费的DynUDNS。运行DynUDNS我应该为客户端的套接字提供什么IP地址?如果可能,请提及确切的步骤(我是abeginner)