Click here to Skip to main content
15,899,825 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCString Pin
sidkraft4-Oct-07 16:46
sidkraft4-Oct-07 16:46 
AnswerRe: CString Pin
bob169724-Oct-07 18:39
bob169724-Oct-07 18:39 
AnswerRe: CString Pin
ThatsAlok4-Oct-07 19:22
ThatsAlok4-Oct-07 19:22 
GeneralRe: CString Pin
Michael Dunn4-Oct-07 20:57
sitebuilderMichael Dunn4-Oct-07 20:57 
GeneralRe: CString Pin
ThatsAlok5-Oct-07 0:30
ThatsAlok5-Oct-07 0:30 
GeneralRe: CString Pin
Hamid_RT5-Oct-07 0:56
Hamid_RT5-Oct-07 0:56 
AnswerRe: CString Pin
David Crow5-Oct-07 3:25
David Crow5-Oct-07 3:25 
QuestionSockets Pin
Adno4-Oct-07 16:02
Adno4-Oct-07 16:02 
im following this article here not quite getting it to work Frown | :(
http://www.codeproject.com/internet/beginningtcp_cpp.asp


Listening for connection code:
int ListenOnPort(int portno, HWND hwnd)
{
SOCKET s;
WSADATA w;
int error = WSAStartup (0x0202, &w); // Fill in WSA info

if (error)
{
return false; //For some reason we couldn't start Winsock
}

if (w.wVersion != 0x0202) //Wrong Winsock version?
{
WSACleanup ();
return false;
}

SOCKADDR_IN addr; // The address structure for a TCP socket

addr.sin_family = AF_INET; // Address family
addr.sin_port = htons (portno); // Assign port to this socket

//Accept a connection from any IP using INADDR_ANY
//You could pass inet_addr("0.0.0.0") instead to accomplish the
//same thing. If you want only to watch for a connection from a
//specific IP, specify that //instead.
addr.sin_addr.s_addr = htonl (INADDR_ANY);

s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); // Create socket

if (s == INVALID_SOCKET)
{
return false; //Don't continue if we couldn't create a //socket!!
}

if (bind(s, (LPSOCKADDR)&addr, sizeof(addr)) == SOCKET_ERROR)
{
//We couldn't bind (this will happen if you try to bind to the same
//socket more than once)
return false;
}

//Now we can start listening (allowing as many connections as possible to
//be made at the same time using SOMAXCONN). You could specify any
//integer value equal to or lesser than SOMAXCONN instead for custom
//purposes). The function will not //return until a connection request is
//made

int tempi = listen(s, SOMAXCONN);
WSAAsyncSelect (s, hwnd, MY_MESSAGE_NOTIFICATION, (FD_ACCEPT | FD_CONNECT |FD_READ | FD_CLOSE));

//Don't forget to clean up with CloseConnection()!
closesocket(s);
::MessageBox(NULL,"Done Listening ", "Got Request..", MB_OK);

}

//--------------

Look out for the events code:

switch (message)
{
case MY_MESSAGE_NOTIFICATION: //Is a message being sent?
{
switch (lParam) //If so, which one is it?
{
case FD_ACCEPT:
::MessageBox(NULL,"Done Listening Event", "Got Request..", MB_OK);
//Connection request was made
break;

case FD_CONNECT:
::MessageBox(NULL,"Done Listening Event", "Got Request..", MB_OK);
//Connection was made successfully
break;

case FD_READ:
//Incoming data; get ready to receive
break;

case FD_CLOSE:
//Lost the connection
::MessageBox(NULL,"Done Listening Event", "Got Request..", MB_OK);
break;
}
}
break;

case WM_KEYDOWN:
ListenOnPort(888, hWnd);
break;
..

the problem is i dont' seem to be getting any of these events FD_ACCEPT | FD_CONNECT |FD_READ | FD_CLOSE
AnswerRe: Sockets Pin
Mark Salsbery5-Oct-07 6:32
Mark Salsbery5-Oct-07 6:32 
Questionpreprocessor, pragma, dll, and paths Pin
bob169724-Oct-07 15:49
bob169724-Oct-07 15:49 
QuestionMerge 3 or more CSV file by date into 1 csv file Pin
jsmotu4-Oct-07 12:20
jsmotu4-Oct-07 12:20 
QuestionRe: Merge 3 or more CSV file by date into 1 csv file Pin
George L. Jackson4-Oct-07 12:33
George L. Jackson4-Oct-07 12:33 
AnswerRe: Merge 3 or more CSV file by date into 1 csv file Pin
Iain Clarke, Warrior Programmer5-Oct-07 5:41
Iain Clarke, Warrior Programmer5-Oct-07 5:41 
Questionhow would i Pin
MMaines20054-Oct-07 9:52
MMaines20054-Oct-07 9:52 
QuestionRe: how would i Pin
Mark Salsbery4-Oct-07 10:01
Mark Salsbery4-Oct-07 10:01 
AnswerRe: how would i Pin
Hamid_RT4-Oct-07 10:16
Hamid_RT4-Oct-07 10:16 
GeneralRe: how would i Pin
Mark Salsbery4-Oct-07 10:26
Mark Salsbery4-Oct-07 10:26 
QuestionRe: how would i Pin
MMaines20054-Oct-07 15:13
MMaines20054-Oct-07 15:13 
AnswerRe: how would i Pin
Hamid_RT4-Oct-07 23:24
Hamid_RT4-Oct-07 23:24 
AnswerRe: how would i Pin
Mark Salsbery5-Oct-07 5:49
Mark Salsbery5-Oct-07 5:49 
AnswerRe: how would i Pin
Hamid_RT4-Oct-07 10:16
Hamid_RT4-Oct-07 10:16 
GeneralRe: how would i Pin
MMaines20056-Oct-07 6:24
MMaines20056-Oct-07 6:24 
GeneralRe: how would i Pin
Hamid_RT6-Oct-07 19:31
Hamid_RT6-Oct-07 19:31 
QuestionIMHO Pin
marc.bellario4-Oct-07 9:02
marc.bellario4-Oct-07 9:02 
AnswerRe: IMHO Pin
led mike4-Oct-07 9:43
led mike4-Oct-07 9:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.