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!

GUI Winsock Server

Status
Not open for further replies.

msstrang

Programmer
Sep 19, 2005
62
US
I hope someone might be able to lead me in the right direction.

I currently have a winsock server application that I've written - it works fine as a console application. My problem is I want it to be a Windows Forms application.

When the server application goes into listen mode waiting for a client the buttons on the Form are not accessable (the mouse pointer turns into an hourglass when hovering over the form).

I know there is a solution to this - but can't seem to get there on my own. I'm guessing I need to make the form Modeless? I used MSVC2005 to create a Windows form project and I'm 99% sure that this method gets you a modal form.

Again, I would really appreciate ANY help in this matter as I'm fairly frustrated.

Thanks,
Marcus
 
The problem is with threading. Your main thread (the one the form is running on) is being taken over by the winsock methods. Spawn a new thread and start the listen method on the new thread. You also need to set up a callback on the main thread so that when something comes in (or needs to be handled) you use the call back to update your main thread.
 
What you are saying is defintly a good help - thank you.

I've looked around and tried some of the threading sources I find - but can't get any to compile ( a common issue when I try something for the first time:))

Just to make sure I'm not spinning my wheels - I am running vc 2005 EXPRESS. It's looking like I'll need MFC to do this? Or can threading be done without the MFC?

 
AFAIK you don't have to use MFC for threading in VC2005 Express. I haven't used that particular version of the compiler...but I would consider it a serious flaw if it restricted the use of threads.

The namespace you need to add is System::Threading. There's a tutorial on MSDN at
 
You're right, that tutorial really got me going in correct direction - now i'm going to have to figure our the callback so I can add items to my listbox so the user knows what is happening.

I hate to ask since you've been so much help already, but can you point me in the direction of a good example for a callback?

I need to update the listbox to disply that the "server is started" and then return to the winsock thread until a client connects

then update the listbox to advise "client connected" and then return to the winsock thread until data is read,
etc.
 
If you want to accumulate the messages in the list box:

Code:
SendMessage( listbox, LB_INSERTSTRING, -1, (LPARAM) string );

To put new messages at the top, use 0 instead of -1.

PostMessage might work better for you tho. I haven't sent messages from a thread in a while.

In any case, the listbox should repaint itself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top