Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sockets and Messages (and communication with GUI)

Status
Not open for further replies.

abcfantasy

Programmer
Jun 3, 2006
110
DK
I have a class (named Server) to handle multiple client connections, receive and send messages and so on.

What I wish to do is the following:

I have a method in that class which is called whenever a message is received from a client. In this method, I want some way to communicate to the Form class, and write that message on a textbox.

Just for the information, from my Form class, I create a Server object, then just call a method AcceptConnections which will create the listening port, accept client connections and start to receive messages.

I'm wondering if this is simple as it sounds, and maybe I'm thinking in a too 'complex' way. I tried using delegates but had problems with Cross threading. And I can't directly access the textbox, since I do not have a reference to the instance of the Form.

Any help is greatly appreciated
Thank you in advance
Andrew

ABC -
 
3 things:

1. You may want to consider Remoting rather than raw sockets - depending if you want to connect to your server using other languages or not.

2. Don't just call your delegates directly from the listening thread. Instead invoke the delegates.

3. Create a Model-View-Controller. Your data (model) should know absolutely nothing about your form (view). Instead your data should tell the controller that it has received something and the controller should tell your form via the observer pattern or something similar.

For a few examples, you can go to the msdn.microsoft.com website and search for 101 C# samples. Give it a download and look in the advanced networking folder.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top