Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old May 25th, 2006, 5:15 PM   #1
hbe02
Hobbyist Programmer
 
hbe02's Avatar
 
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3 hbe02 is on a distinguished road
Wsanetworkevents

alright what i want to do is listen to a socket for something to be recieved from the client side. in that time, i want to keep couting "there"
and when i recieve something, it trigerrs a network event.
this is what my main looks like:
com->sd returns the socket descriptor integer.
char*buffer = new char[50];

WSANETWORKEVENTS NetworkEvents;
HANDLE NetworkEvent;
::WSAEventSelect(com->sd, NetworkEvent,  FD_ACCEPT );

if ((WSAWaitForMultipleEvents(1, &NetworkEvent, FALSE,WSA_INFINITE, FALSE))== WSA_WAIT_FAILED)
		cout<<"error1"<<endl;
if (WSAEnumNetworkEvents(com->sd ,NetworkEvent, &NetworkEvents) == SOCKET_ERROR)
         cout<<"error2"<<endl;
while(true)
 {
     if (NetworkEvents.lNetworkEvents & FD_ACCEPT)
      {
           if (NetworkEvents.lNetworkEvents & FD_ACCEPT &&  NetworkEvents.iErrorCode [FD_ACCEPT_BIT] == 0)
           {
				 cout<<"here";
				 break;      	
           }
           else
           {
                  cout<<"\rthere";
				  com->Recieve(host,buffer);
           }
    }
}
and this is the com->Recieve(host,buffer) function
bool Mysocket::Recieve(sockaddr_in & client, char * & buffer)
{
	int clen = sizeof (sockaddr_in);
	cout<<"Listening on Socket "<<sd<<"...."<<endl;
		listen(sd,1);   //listen to created socket for connection (1 connection max)
	
		if(accept(sd,0,0) != -1) //accept connection on socket
		{
			return false;	
		}
		else
		{
			char* temp = new char[25000];
		
			int size = 	recvfrom(sd,temp,strlen(temp),0,(struct sockaddr *) &client,&clen);	//get recieved input and put in temp
			
			for (int i = 0 ; i <size ; i++)
			{
				buffer[i] = temp[i];
			}
			buffer[i] = NULL;
			
			
			delete temp;
			return true;
		
		}
		
}

this is the first time i use WSAevents, i cant seem to find a good resource to learn more, i have a feeling the structure is all wrong and all over the place.

Appreciate the help guys.
hbe02 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC