views:

214

answers:

1

I've written a multithreaded server that uses tcplistener and a client handler class that controls input and output. I also have a GUI chat client. The chat client works fine and the console version of the server also works well.

I have a start() method in the partial(?) Form class, which I run from a new thread when I click a button, that starts the TCP Listener and loops through and accepts socket requests. For every request a new ClientHandler object is created and the socket is passed to this object before being used in a new handler thread.

The ClientHandler is a different class to the form and I'm having real problems writing data to the Listbox in the Form class from within the ClientHandler class. I've tried a few different ways of doing this but none of them work as they involve creating a new form class within the ClientHandler.

Any help or advice on what I should be reading to help me would be really appreciated.

A: 

OK problem solved:

I pass the ServerGUI to the ClientHandler class like this:

ClientHandler handler = new ClientHandler(clientSocket, "Client " + id.ToString(),this);

and then I can do whatever I want. Few that took me 2 hours!

SlowForce
One thing you might want to consider is that the design you've described is putting your ClientHandler in charge of updating the GUI. If you were to change the design so that the ClientHandler provides events notifying of changes and the GUI consumes the events, then you would have flexibility to change the GUI in the future without effecting the ClientHandler code.
Dan Bryant