how to monitor the socket at client side in java

H

huwind

I am writing a client/server based instant messenger in java and have
the problem to monitor the incoming massages via socket on the client
side.

I have some GUI widnows for login, select a contact to talk, and the
chat window. What I wanna implement is that after the user login, a
monitoring thread will be created and it listens to the port. Once
there is a message coming in, it calls methdds to process the message
acccroding to the messge types.

The problems I have now are:
1. I have a worker thread, say myListener, to listen to the port. The
listening work in done by an infinite loop which reads the content of
the input stream of the socket. But when I call myListener.start(), it
seems that the thread myListener isn't executed. How can I monitor the
socket on the client side?
2. How can I get the active window?

Any help will be appreciated.
 
N

Neil Campbell

huwind said:
I am writing a client/server based instant messenger in java and have
the problem to monitor the incoming massages via socket on the client
side.

I have some GUI widnows for login, select a contact to talk, and the
chat window. What I wanna implement is that after the user login, a
monitoring thread will be created and it listens to the port. Once
there is a message coming in, it calls methdds to process the message
acccroding to the messge types.

To monitor for a connection on a port, the easiest way is to create a
ServerSocket that listens on that port. For details see:

http://java.sun.com/j2se/1.4.2/docs/api/java/net/ServerSocket.html
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top