Making GUI yield to a thread

M

mike

I have just been doing some testing and learning on writing threads and
servers in java. I have a gui, that immediately starts a thread which
opens a socket. That all works fine, and a netstat in linux verifies
that the port has been opened. When I use the client I wrote to
connect to the socket, it tries to connect and just sits there. Never
connects. Also, I have noticed that if I telnet into the port, the
initial welcome message that the socket is suppose to send out upon
connection never gets sent. If I don't use the gui, and just run a
driver program which starts the socket and then try to connect to it,
it connects just fine. So I guess I have narrowed down the problem to
the GUI not giving time to the socket to do it's thing. I have tried
setting the priorities of the socket to 10 or max_priority, but still
nothing. Is there something I am missing?
 
M

Matt Humphrey

mike said:
I have just been doing some testing and learning on writing threads and
servers in java. I have a gui, that immediately starts a thread which
opens a socket. That all works fine, and a netstat in linux verifies
that the port has been opened. When I use the client I wrote to
connect to the socket, it tries to connect and just sits there. Never
connects. Also, I have noticed that if I telnet into the port, the
initial welcome message that the socket is suppose to send out upon
connection never gets sent. If I don't use the gui, and just run a
driver program which starts the socket and then try to connect to it,
it connects just fine. So I guess I have narrowed down the problem to
the GUI not giving time to the socket to do it's thing. I have tried
setting the priorities of the socket to 10 or max_priority, but still
nothing. Is there something I am missing?

So if I understand you, your gui starts a thread that opens a TCP listening
(server) socket. However, you find that clients cannot connect, or if they
do the socket does not respond. Yet when you run your program (presumably
exactly the same code) it works fine. It my experience the gui has nothing
to do with this--it sounds to me more like you really aren't starting your
server correctly. Are you sure you're calling thread.start ()? You will
need to show the code that establishes the server in order to get a clearer
answer.

Cheers,
Matt Humphrey (e-mail address removed) http://www.iviz.com/
 
M

mike

Man, I hate these dumb mistakes. You were right. I created a new
instance of the server, but never called the start() method. Good call
though. I looked at that part of the code so many times and just
didn't realize it.
 
O

Oliver Wong

mike said:
I have just been doing some testing and learning on writing threads and
servers in java. I have a gui, that immediately starts a thread which
opens a socket. That all works fine, and a netstat in linux verifies
that the port has been opened. When I use the client I wrote to
connect to the socket, it tries to connect and just sits there. Never
connects. Also, I have noticed that if I telnet into the port, the
initial welcome message that the socket is suppose to send out upon
connection never gets sent. If I don't use the gui, and just run a
driver program which starts the socket and then try to connect to it,
it connects just fine. So I guess I have narrowed down the problem to
the GUI not giving time to the socket to do it's thing. I have tried
setting the priorities of the socket to 10 or max_priority, but still
nothing. Is there something I am missing?

Calling Thread.yield() on the GUI thread? Or better yet, Thread.sleep()?
Or better yet, use events to wake up your GUI thread, rather than having it
poll every hundred milliseconds or so?

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top