Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Are there any C# people on here?


Gwen
 Share

Recommended Posts

Ok I have working tcp code for a server that can accept multiple clients.

My question is how do i know when an event happens in my tcp class from my main form class.

Example:
On my main server form page, I want to have a list of connected clients. How do i update that list when a client connects, when the tcp class is the only one that knows if a client connects.

Or if i send a message from the client to the server… the tcp class catches the packet.. does what it needs to do, how would i get the resulting message to a textbox on the main form page.

If i have a messagebox inside my tcp class i can display whatever packet is coming across, i just dont know how to get that info to a different class.

I hope you can decipher that.. im not good at getting out what I want to say.
Link to comment
Share on other sites

"On my main server form page, I want to have a list of connected clients. How do i update that list when a client connects, when the tcp class is the only one that knows if a client connects."
Check if the tcp class has received new connections if so use the other class to update your listbox.

"Or if i send a message from the client to the server… the tcp class catches the packet.. does what it needs to do, how would i get the resulting message to a textbox on the main form page."
Check if the tcp class received a new message and from who use the other class to get your textbox updated.

You don't usually let a class control another class, especially not for networking. You normally get data from class A and use it to handle with class B. You don't usually let class A handle class B if class A has new data.

Regards, Godlord.
Link to comment
Share on other sites

yeah I understand that…

but if the tcp class has the event handler for client connections, how do i know when that event is updated? Do i have to make a seperate variable to keep track of when a new client connects? Or is there a way to tap into the TCP event handler?
Link to comment
Share on other sites

@Gwen:

> yeah I understand that…
>
> but if the tcp class has the event handler for client connections, how do i know when that event is updated? Do i have to make a seperate variable to keep track of when a new client connects? Or is there a way to tap into the TCP event handler?

I wonder why you would work with events though but I'm more a C/C++ man anyway.

Usually an event is a function which gets called so you can either be sure that when a new connection is received to set a variable like bNewConnection as true then you need to check if any of these variables are true if so, set it to false and the event should occur. Well at least if you call the "event".

Regards, Godlord.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...