views:

68

answers:

2

Hello all,

I have been assigned to a task where I need to connect to a socket and receive a lot of updates (3K-4K messages per second) I also need to send some message to server for authentication and configuration.

There is an existing C++ apps given by the data provider and they have no c# sample. I have been trying to write this app with C# but having some difficulties; especially with marshalling structs containing variable length arrays etc.. Am I on the right path to do this?

I have been advised to use PInvoke but looks like I need to first modify their C++ sample to make it API like and then I can invoke it C# properly. And I am not sure about the performance with PInvoke.

A: 

Why not use C++ if the app is already in that?
If there is a reason to use C# I would always re-write the C++ if it is feasable. You would be writing new code in C# so you may as well do a complete migration rather than a cumbersome mixture.
I certainly wouldn't use pinvoke for something like network programming... it's complicated enough as it is without adding that. There's an inevitable performance hit with it although what that is exactly, "it depends".

A: 

P/Invoke has a performance penalty. C# has a very nice networking programming model and I really suggest that you give it another try. The benefit will be that you have a fully managed, more efficient and maintainable application.

Of course if the existing application is huge and you need a lot of time to port it to C#, you could consider p/invoke. However, since you still need to modify it, you lose some of the advantages of this route.

kgiannakakis
Can you a bit elaborate on c#'s "networking programming model"
Otake
You can easily find a lot of information in Google. Everything is done with streams and in my opinion the big advantage is that you can have asynchronous calls for when data are received.
kgiannakakis