Managed C++ - Asynchronous Socket Comm - AsyncCallback


G

Guest

Hello,

I have developped asynchronous socket communication with blocking Socket
commands (accept, connect, send, receive) by using threads on Windows .NET
Forms. It is working properly. Now I want to code the similar program with
Asynchronous Socket commands of .NET using Managed C++ on Windows .NET Forms.
My problem is with delegates. I have to use "static" methods as parameter
in delegate constructor like below:
-----------------------------------------------
static Socket* ServerSocket ;
void Listen() {
...
ServerSocket ->BeginAccept(new AsyncCallback( 0,
&frmAsySERVER::AcceptCallback), ServerSocket );
...
}

static void AcceptCallback(IAsyncResult* ar) {
...
Socket* listener = __try_cast<Socket*>(ar->AsyncState);
ServerSocket = listener->EndAccept(ar);

StateObject* state = new StateObject();
state->workSocket = ServerSocket;
ServerSocket->BeginReceive(state->buffer,
0,
StateObject::BufferSize,
SocketFlags::None,
new AsyncCallback(0,
&frmAsySERVER::ReadCallback),
state);
}
--------------------------------------------

My problem is at the Asynchronous Socket Commands' callbacks. Is "static
void AcceptCallback(IAsyncResult* ar)" is not "static, I cannot call it from
"ServerSocket ->BeginAccept(new AsyncCallback( 0,
&frmAsySERVER::AcceptCallback), ServerSocket );" .
Isn't there any AsyncCallback constructor creation as easy as in C#.
Managed C++ -> "new AsyncCallback( 0, &frmAsySERVER::AcceptCallback)"
C# -> new AsyncCallback( AcceptCallback)

I cannot write some information onto listboxes , textboxes , labels on the
Windows .NET Forms from the "static" functions, unless they are not "static".

~~~~~~~~~~~~~~~~~~~
İyi Çalışmalar
Alper AKÇAYÖZ (Bil Muh)

Wish You Good Work
Alper AKCAYOZ (Bil Muh)
 
Ad

Advertisements

G

Guest

CORRECTION

My problem is at the Asynchronous Socket Commands' callbacks. IF "static
void AcceptCallback(IAsyncResult* ar)" is not "static, I cannot call it from
"ServerSocket ->BeginAccept(new AsyncCallback( 0,
&frmAsySERVER::AcceptCallback), ServerSocket );" .
Isn't there any AsyncCallback constructor creation as easy as in C#.
Managed C++ -> "new AsyncCallback( 0, &frmAsySERVER::AcceptCallback)"
C# -> new AsyncCallback( AcceptCallback)

I cannot write some information onto listboxes , textboxes , labels on the
Windows .NET Forms from the "static" functions, unless they are not "static".

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top