LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-07-2007, 09:29 AM   #1
Hady
Member
 
Registered: Nov 2003
Posts: 55

Rep: Reputation: 15
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
 
Old 01-08-2007, 02:37 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Java question newbz Programming 2 10-06-2006 12:08 PM
simple java question newbz Programming 18 09-29-2006 08:29 PM
connection between java socket and unix socket sathishkumar Programming 1 01-10-2006 03:21 PM
simple java question? Schizo265 Programming 2 07-15-2003 04:20 AM
Simple Java question Citizen Bleys Programming 6 04-04-2002 02:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration