Java客户端服务器连接问题

编程入门 行业动态 更新时间:2024-10-12 16:24:01
本文介绍了Java客户端服务器连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经打了好几个小时,似乎找不到问题。当我的服务器运行并按下连接按钮时,gui冻结直到客户端gui终止..然后gui再次激活并显示消息。 这是我的服务器代码:

Hi i''ve been batteling for hours and can''t seem to find the problem. When my server runs and I press the connect button the gui freezes until the client gui is terminated.. only then the gui becomes active again and displays the messages. Here is my server code:

展开 | 选择 | Wrap | 行号 推荐答案

@ Elaine121 我没有阅读你的所有代码,但鉴于你的描述,我得出结论你在EDT线程(事件调度线程)中进行所有处理。你正在让那个线程忙于你的accept()和read()调用;他们阻止方法,即他们完成工作之前不会回来。美国东部时间不再有任何时间来完成它的工作:绘画组件和听取事件。 在另一个线程中完成所有处理,以便EDT可以完成其工作你做你的工作。 亲切的问候, Jos @Elaine121 I didn''t read all your code but given your description I conclude that you do all your processing in the EDT thread (Event Dispatch Thread). You are keeping that thread busy with your accept() and read() calls; they are blocking methods, i.e. they don''t return until they have done their job. The EDT doesn''t have any time anymore to do its job: painting components and listening for events. Do all of your processing in another thread so the EDT can do its job while you do your job. kind regards, Jos

我不是那样的熟悉线程。最好的方法是什么? i''m not that familiar with threads. What''s the best way to do that?

@ Elaine121 创建处理Runnable接口的实现所有套接字通信;将它提供给新的线程并启动线程。这基本上就是它。 亲切的问候, Jos @Elaine121 Create an implementation of the Runnable interface that handles all the socket communication; feed it to a new Thread and start the thread. That''''s basically it. kind regards, Jos

更多推荐

Java客户端服务器连接问题

本文发布于:2023-11-12 10:24:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581218.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   服务器   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!