LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Simple Java Socket Question (https://www.linuxquestions.org/questions/programming-9/simple-java-socket-question-517130/)

Hady 01-07-2007 09:29 AM

Simple Java Socket Question
 
Hi,

I am a Newbie in Java.
I have this code
Code:


Socket sc = serverSocket.accept();
ClientThread ct = new ClientThread(sc);
ct.start();

Can I send messages to the thread after it is started?

Can I add a function 'connect' in the clientThread class, and call later ct.connect() ??

I tried doing so, but it didn't work,
I want to know if it always doesn't work (not be able to connect to the thread after you run it)
or because my code is wrong

Thanks,

Happy New Year

jlliagre 01-08-2007 02:37 AM

You cannot call a thread's method from another thread and expect it will affect the target thread.

For an explanation, look for "Threads are not Objects" in http://www.javaworld.com/cgi-bin/mailto/x_java.cgi


All times are GMT -5. The time now is 03:32 PM.