Click to See Complete Forum and Search --> : About asynchronous Socket,Why not work?


sarcophile
July 19th, 2003, 05:03 AM
private: System::Void btn_rcv_Click(System::Object * sender, System::EventArgs * e)
{
.......

IPAddress* pIPA = IPAddress::Parse(S"10.5.12.17");
IPEndPoint* pIPE = new IPEndPoint(pIPA,4050);
skt ->Bind(pIPE); // skt is a public member of this class: Socket* skt;
skt ->Listen(backlog);
AsyncCallback* pAc = new AsyncCallback(this,&Form1::ACallback);
skt->BeginAccept(pAc,skt);
}

void ACallback(IAsyncResult* ARes)
{
MessageBox::Show("accepted"); // this message does not display
Socket* s = __try_cast<Socket*>(ARes->AsyncState);
timer1->Enabled = true;
ps2 = s->EndAccept(ARes); // ps2 is another Socket*
}

Now the function ACallback(..) is not called. According to MSDN, when I call BeginAccept, a new thread will begin and it will call ACallback, and the new thread will suspend on EndAccept(), but now nothing happens, the message "accepted" does not display, and timer1 not enabled, why?
:confused: