我无法让多个小程序与我的 Cpp 服务器通信
由于某种原因,当我将一个 Java 客户端连接到我的 Cpp 服务器时,它工作得很好。但是,当除第一个 Java 小程序之外的另一个 Java 小程序尝试连接时,它会连接,但会停止从服务器接收数据。其他一些尝试会完全冻结该小程序。我在网上到处搜索但一无所获。我将不胜感激有关该主题的任何帮助,例如建议、链接或来源。我唯一的其他选择(因为 Flash 是不可能的)是使用 Active X,但那样我就会失去所有的跨平台能力:(。我的源代码(减去调试代码等)如下。
public void init() {
try {
socket = new Socket("localhost",4000);
} catch (UnknownHostException e) {
System.out.println("Unknown host");
} catch (IOException e) {
System.out.println("IO Exception");
return;
}
BufferedReader fromServer = null;
PrintWriter toServer = null;
fromServer = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
toServer =
new PrintWriter(socket.getOutputStream(), true);
toServer.flush();
For some reason when I connect one Java client to my Cpp server it works perfectly. But when another Java applet tries to connect in addition to the first, it does but it stops receiving data from the server. Some of the other attempts would completly freeze the applet. I have searched everywhere on the 'net but found nothing. I would appreciate any help on the subject like advice, links or source. My only other option (since Flash is out of the question) is to use Active X, but then I would lose all my crossplatform-ability :(. My source (minus debugging code and so on) follows.
public void init() {
try {
socket = new Socket("localhost",4000);
} catch (UnknownHostException e) {
System.out.println("Unknown host");
} catch (IOException e) {
System.out.println("IO Exception");
return;
}
BufferedReader fromServer = null;
PrintWriter toServer = null;
fromServer = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
toServer =
new PrintWriter(socket.getOutputStream(), true);
toServer.flush();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来你的 Cpp 服务器无法处理多个连接。您能否验证是否可以接受多个传入网络连接?
It sounds like your Cpp server can't handle multiple connections. Can you verify that you can accept more than one incoming network connection?
我找到了解决方案!您无法在一个浏览器和一台机器上运行多个小程序。如果您将它们加载到单独的浏览器(如 IE 和 FF)中或将其加载到单独的计算机上(如远程),它将起作用。我希望这有帮助。
I found the solution! You can't run multiple applets in one browser and one machine. It will work if you load them in seperate browsers (like IE and FF) or load it on a seperate machine (like remotely). I hope this helps.