threads
Hi ...
I have a problem with threads ...
How do I do this properly?
Whenever a button is pushed ... I want a thread to start ... connect to a server and both listen for and send messages to it ...
Id like to be able to connect to multiple servers at the same time.
I have done a couple of attempts but neither one worked well ... Im looking for a book on the topic, but meanwhile ... please help :)
[436 byte] By [
tvaetta] at [2007-10-2 21:19:42]

Your question is vague.
What is it exactly you are having trouble with:
- How to start a thread?
- How to create a GUI with a button and have a method called when the button is pushed?
- Connect to the server, sending and receiving messages?
If you want useful help, describe in more detail what you tried and why it did not work well (and what you mean exactly by "it didn't work well").
Here are some pointers:
[url=http://java.sun.com/docs/books/tutorial/essential/threads/index.html]Threads: Doing Two or More Tasks at Once[/url]
[url=http://java.sun.com/docs/books/tutorial/uiswing/index.html]Creating a GUI with JFC/Swing[/url]
[url=http://java.sun.com/docs/books/tutorial/networking/index.html]Custom Networking[/url]
euhm ... its too much code to paste.
The original error was the threads worked on the same class variables. I have a class implementing Runnable interface, containing a socket, readers, writers and a list of channels.
From the main gui, when the button is pressed an object of that class is created. Additionally the object itself have a connect button, when it is pressed it fires up a thread listening to a server.
The problem was that when I had two objects ... one received messages directed to the other and channels were only added to the channellist in the
first object.
I've tried many thing ... and Id like to see an example design of this. Tutorials often just covers mutliple threaded servers or too basic client examples.
I'll check the links ... =)