Thanks all for your responses,
Ya Pawan, you were right, the problem was with client code and after
changing what you told me to do, it works fine.
However,i'm still not able to figure where the problem existed, i mean
i still can't understand what was the mistake. I mean, i'm kind of confused
with this whole threading issues. Let me explain my confusion:
Let us analyse the solution "I POSTED EARLIER" step by step from Client
point of view:
1)I created a new thread which implements run function. Thus there are two
threads: one main and other implementing run. Both get executes time to time
depending upon the scheduler.
2)in the run function i created a socket which connects to server at port no
5100:
ss = new Socket(InetAddress.getByName("Invictus-PC"),5100);
3)i fetch the output stream for writing to the socket(i.e. sending data to
the server)
output = new
ObjectOutputStream<http://java.sun.com/javase/6/docs/api/java/io/ObjectOutputStream.html>
(ss.getOutputStream());
4)now i create a server socket at port no 5000:
ssoc = new
ServerSocket<http://java.sun.com/javase/6/docs/api/java/net/ServerSocket.html>
(5000);
5)now an infinite loop :
in which we wait for request to come:
sen = ssoc.accept();
this thread then hangs until the request comes(or does it mean that the
whole program hangs until the request comes? please clarify)
However if the main thread is still working, whenever send button is
pressed, the data should be send to the client using the output stream of
the socket created to connect to the server in step 1 of run function(that
is what was happening,data was being send everytime the send button is
pressed,it was happening, that indeed means that main was working and the
other thread was at hang and waiting for request to come, now if that is the
case why is ssoc.accept() a problem??? and since the data is being sent to
the server why is it not accepting and how is server accepting the
data(server's working) related to ssoc.accept() blocking the execution)
And one more thing: i fetch the output stream in step 2(as shown above).
This stream is used in the send button code(which is in the main function) I
know it is happening but i just want to clarify that can we use an
object(initialised in one thread) in another thread?
PS: I tried my level best to explain you the confusion, I'm really messed
up.
And as far as the call to actionPerformed is needed, everytime the
send button is clicked the call is made and that is why the handler is for.
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en