Java客户端服务器连接问题 [英] Java client server connection problem

查看:167
本文介绍了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客户端服务器连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆