andremussche / DelphiWebsockets

Websockets and Socket.io for Delphi
251 stars 127 forks source link

Using with CBuilder rathe than Delphi #20

Open datkins47 opened 7 years ago

datkins47 commented 7 years ago

Hi,

Testing the C++ Builder Berlin, all the lib code compiles just fine as far as I can tell but need to translate demo apps to C++, any pointers, I have most of it but this section I'm not sure of the way to make work in C++

server.SocketIO.OnEvent(C_CLIENT_EVENT, procedure(const ASocket: ISocketIOContext; const aArgument: TSuperArray; const aCallback: ISocketIOCallback) begin //show request (threadsafe) ShowMessageInMainthread('REQUEST: ' + aArgument[0].AsJSon); //send callback (only if specified!) if aCallback <> nil then aCallback.SendResponse( SO(['succes', True]).AsJSon ); end);

the procedure is the problem, I suspect its my lack of understanding on what delphi is doing here that's the issue,

any ideas?

thanks,

david

andremussche commented 7 years ago

I can't help you right now, I haven't done any C++Builder projects with Delphi code. Do you have some demo/example project for me?

2017-01-16 9:05 GMT+01:00 David Atkins notifications@github.com:

Hi,

Testing the C++ Builder Berlin, all the lib code compiles just fine as far as I can tell but need to translate demo apps to C++, any pointers, I have most of it but this section I'm not sure of the way to make work in C++

server.SocketIO.OnEvent(C_CLIENT_EVENT, procedure(const ASocket: ISocketIOContext; const aArgument: TSuperArray; const aCallback: ISocketIOCallback) begin //show request (threadsafe) ShowMessageInMainthread('REQUEST: ' + aArgument[0].AsJSon); //send callback (only if specified!) if aCallback <> nil then aCallback.SendResponse( SO(['succes', True]).AsJSon ); end);

the procedure is the problem, I suspect its my lack of understanding on what delphi is doing here that's the issue,

any ideas?

thanks,

david

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/andremussche/DelphiWebsockets/issues/20, or mute the thread https://github.com/notifications/unsubscribe-auth/AC5IjgnEQmf3nnHuYKPIXMu6yK9h6s8Zks5rSyTBgaJpZM4LkRbe .

datkins47 commented 7 years ago

Hi,

I have left it running connected and can see heartbeats/pings happening so the basics are running.

WebSocketServer = new TIdWebsocketServer(this);
WebSocketClient = new TIdHTTPWebsocketClient(this);

WebSocketServer->DefaultPort = 12345;

// the follwoing is the issue setting up the event // WebSocketServer->SocketIO->OnEvent( C_SERVER_EVENT, Temp ); WebSocketServer->Active = true; WebSocketServer->OnMessageBin = WebsocketMessageBin; WebSocketServer->OnMessageText = WebsocketMessageText;

WebSocketClient->Host = "localhost";
WebSocketClient->Port = 12345;
WebSocketClient->SocketIOCompatible = true;
WebSocketClient->Connect();

WebSocketClient->SocketIO->Emit( C_CLIENT_EVENT, "request some data" );

The header defines this as

void __fastcall OnEvent(const System::UnicodeString aEventName, const _di_TSocketIOEvent aCallback);

_di_TSocketIOEvent is defined as

__interface TSocketIOEvent; typedef System::DelphiInterface _di_TSocketIOEvent;

So i'm not sure how to achieve what happens in the Delphi code in C++

David

andremussche commented 7 years ago

in Delphi the "_di_TSocketIOEvent" is an anonymous method defined as: TSocketIOEvent = reference to procedure(const ASocket: ISocketIOContext; const aArgument: TSuperArray; const aCallback: ISocketIOCallback);

An anonymous method is actually the same as an interface with an "Invoke" like this ISocketIOEvent = interface procedure Invoke(const ASocket: ISocketIOContext; const aArgument: TSuperArray; const aCallback: ISocketIOCallback); end

I hope this helps?

2017-01-16 23:27 GMT+01:00 David Atkins notifications@github.com:

Hi,

I have left it running connected and can see heartbeats/pings happening so the basics are running.

WebSocketServer = new TIdWebsocketServer(this); WebSocketClient = new TIdHTTPWebsocketClient(this);

WebSocketServer->DefaultPort = 12345;

// the follwoing is the issue setting up the event // WebSocketServer->SocketIO->OnEvent( C_SERVER_EVENT, Temp ); WebSocketServer->Active = true; WebSocketServer->OnMessageBin = WebsocketMessageBin; WebSocketServer->OnMessageText = WebsocketMessageText;

WebSocketClient->Host = "localhost"; WebSocketClient->Port = 12345; WebSocketClient->SocketIOCompatible = true; WebSocketClient->Connect();

WebSocketClient->SocketIO->Emit( C_CLIENT_EVENT, "request some data" );

The header defines this as

void __fastcall OnEvent(const System::UnicodeString aEventName, const _di_TSocketIOEvent aCallback);

_di_TSocketIOEvent is defined as

__interface TSocketIOEvent; typedef System::DelphiInterface _di_TSocketIOEvent;

So i'm not sure how to achieve what happens in the Delphi code in C++

David

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/andremussche/DelphiWebsockets/issues/20#issuecomment-272976293, or mute the thread https://github.com/notifications/unsubscribe-auth/AC5Ijm-N8QDdAB06yQBzg2cUuvt1Ng6oks5rS-7ggaJpZM4LkRbe .

datkins47 commented 7 years ago

Hi,

Makes sense, my issue is with transferring that into C++, I have reached out to Embarcadero for guidance if I get something will check in a sample c++ project to github

David

From: André Mussche [mailto:notifications@github.com] Sent: Wednesday, January 18, 2017 8:11 AM To: andremussche/DelphiWebsockets Cc: David Atkins; Author Subject: Re: [andremussche/DelphiWebsockets] Using with CBuilder rathe than Delphi (#20)

in Delphi the "_di_TSocketIOEvent" is an anonymous method defined as: TSocketIOEvent = reference to procedure(const ASocket: ISocketIOContext; const aArgument: TSuperArray; const aCallback: ISocketIOCallback);

An anonymous method is actually the same as an interface with an "Invoke" like this ISocketIOEvent = interface procedure Invoke(const ASocket: ISocketIOContext; const aArgument: TSuperArray; const aCallback: ISocketIOCallback); end

I hope this helps?

2017-01-16 23:27 GMT+01:00 David Atkins notifications@github.com:

Hi,

I have left it running connected and can see heartbeats/pings happening so the basics are running.

WebSocketServer = new TIdWebsocketServer(this); WebSocketClient = new TIdHTTPWebsocketClient(this);

WebSocketServer->DefaultPort = 12345;

// the follwoing is the issue setting up the event // WebSocketServer->SocketIO->OnEvent( C_SERVER_EVENT, Temp ); WebSocketServer->Active = true; WebSocketServer->OnMessageBin = WebsocketMessageBin; WebSocketServer->OnMessageText = WebsocketMessageText;

WebSocketClient->Host = "localhost"; WebSocketClient->Port = 12345; WebSocketClient->SocketIOCompatible = true; WebSocketClient->Connect();

WebSocketClient->SocketIO->Emit( C_CLIENT_EVENT, "request some data" );

The header defines this as

void __fastcall OnEvent(const System::UnicodeString aEventName, const _di_TSocketIOEvent aCallback);

_di_TSocketIOEvent is defined as

__interface TSocketIOEvent; typedef System::DelphiInterface _di_TSocketIOEvent;

So i'm not sure how to achieve what happens in the Delphi code in C++

David

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/andremussche/DelphiWebsockets/issues/20#issuecomment-272976293, or mute the thread https://github.com/notifications/unsubscribe-auth/AC5Ijm-N8QDdAB06yQBzg2cUuvt1Ng6oks5rS-7ggaJpZM4LkRbe .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/andremussche/DelphiWebsockets/issues/20#issuecomment-273410067 , or mute the thread https://github.com/notifications/unsubscribe-auth/AO7cG4P2b_HNB6DUM160du7vHeshX7Kmks5rTckMgaJpZM4LkRbe . https://github.com/notifications/beacon/AO7cG9Squ-ck3TTSP9AXjouQOmxrE_Kvks5rTckMgaJpZM4LkRbe.gif