关于socket建链及对象实例的唯一性控制问题

njallenwang 2002-02-07 09:42:18
作为clientSocket,如何判断本机与某特定IP特定port的serverSocket之间已经有一条链路存在.我的目的是在同一主机上控制同时起多个client应用程序,或者问题转换为在一个虚拟机中如何防止另外的虚拟机也起了同样的对象
...全文
65 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wolfsquare 2002-02-08
  • 打赏
  • 举报
回复
事实上通过socket不是最简便的方法,既然你不想固定端口。
那你还可以通过写文件方式来判断,例如程序启动后判断当前路径是否存在log.txt文件,没有就创建一个。再就是编写本地方法做进程间通讯了。
njallenwang 2002-02-08
  • 打赏
  • 举报
回复
go on
njallenwang 2002-02-08
  • 打赏
  • 举报
回复
adsf
njallenwang 2002-02-08
  • 打赏
  • 举报
回复
wolfsquare(狼平方):如何查询?我不想固定本地端口(localport),因为不太好释放它
gdsean(摇滚java):我不能控制serverSocket
passingguy(英语狂人):不同的jvm里flag怎么起作用?你在huawei混过?现在跑哪了?说清楚给分
gdsean 2002-02-07
  • 打赏
  • 举报
回复
在serverSocket保持一个连接对象就可以了
参见单子设计模式

wolfsquare 2002-02-07
  • 打赏
  • 举报
回复
在本机开一个查询端口,当程序启动时先与该端口通讯查询
passingguy 2002-02-07
  • 打赏
  • 举报
回复
When i work in huawei,
i faced the same question.
i think that it can't be solved by singleton(mentioned by gdsean).

at that time, we just put a flag in the package to determine client.
or , you can distinguish the clients by their ports,they can't be the same.

will you give me points???

23,405

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧