I'm was a web application developer for years. I'm dabbling in programming in a dialog/event environment by writing an app on my AT&T tilt(PPC). big change for me.

I wrote a simple app on my tilt that connects to a server, gets data, and updates some controls with the data. This server will send data about things that change as time goes on. The way I currently have the client program, when the user selects "connect" it will connect, get a snapshot of the data, then log off. then it calls the report screen and updates the dialog controls. To get changes, you have to press the connect button again. It is working to this point!

I need to find out how to code this so the socket will stay open, and somehow I'm notified when data is received on that socket, so that I can recv the data and reprocess it. This is above my skill and my googling isnt finding much on how to do this, especially in a PPC environment. I've wrote this using MS Visual Sudio 8 using C++. It's a very simple application.

So long story short, is there some code sample or example somewhere that shows me how to leave a socket open and be notified when data is coming in?

Thank you!

Recommended Answers

All 4 Replies

So in this example:

struct emprec
{
char name[25];
int age;
int pay;
} employee;

you are saying the we define a struct called emprec. Within that we have an array called name that is the char data type and has 25 components. int age and int pay are common sense...what is the employee that is outside of the bracket?

WSAEventSelect http://msdn2.microsoft.com/en-us/library/aa922328.aspx is probably what you are looking for.
googling on WSAEventSelect tutorial/sample should fetch you quite a few hits. here are two of them
http://www.codersource.net/winsock_tutorial_server_event_model.html
http://www.codeproject.com/KB/IP/networkevents.aspx

Thank you Vijayan.

I did a ton more searching and hacking today. I seem to have my code 90% there. These 2 examples you posted were very helpful. I'm stuck on 1 last thing. I now have the functions "handleData", "sendData", and "InitSocket".

Initsocket gets called in WinMain. works perfectly.
sendData gets called in a few places. Works perfectly.
handleData - which will process reads and closes, etc looks like it will work, but I still don't know how to call this function.

Is there a WM_XXXXX event or something that I can call my handleData with? something like a WM_SOCKET that works with a PPC?

> Is there a WM_XXXXX event or something that I can call my handleData with?
> something like a WM_SOCKET that works with a PPC?
unfortunately no. the win32 WSAAsyncSelect function http://msdn2.microsoft.com/en-us/library/ms741540.aspx does this, but AFAIK, it isn't available for Windows Mobile.

> handleData - which will process reads and closes, etc looks like it will work,
> but I still don't know how to call this function.
easiest way is to create another thread using CreateThread http://msdn2.microsoft.com/en-us/library/bb202727.aspx and in that thread, issue a WSAWaitForMultipleEvents http://msdn2.microsoft.com/en-us/library/aa922422.aspx
to wait for a network event to occur. when the event arrives, call handleData to handle it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.