RDM Sockets - c#

I've recently come across .NET's RDM Socket type (SocketType.Rdm) and its features sound very promising, sounding very much like a reliable connectionless protocol. However, I've found no examples of its usage, and little documentation on the protocol itself.
First of all, how do I instantiate a socket of this type? Specifying SocketType.Rdm in the socket constructor always seems to cause an exception. Secondly, is this protocol referred to by a different name outside of .NET? As I say, the protocol seems to undocumented despite it's promising feature set.
Thanks

RDM sockets do support PGM. However PGM support is not installed on Windows by default, but as part of the MSMQ installation. If you have Windows 7, this is the command line that will prompt Package Manager to install the right components.
pkgmgr /iu:MSMQ-Container;MSMQ-Server;MSMQ-Multicast
Try running your socket after installing this and see if you still have the same exception.

As far as I know this is PGM. Here are some random links to MS forum bits:
devshed,
ms.
I have no idea about the maturity of .NET implementation.

Reliable Multicast with PGM and WCF is an interesting article over at codeproject on how to use RDM (PGM) sockets. It features both raw PGM sender/receiver classes and also builds on it by implementing WCF connectors for PGM

Related

TLS Implementation Silverlight

I am trying to implement TLS client in a Silverlight XMPP application.
I found a nice documentation about TLS at tools.ietf.org, there are a good explanation of structures, but I can't find an explanations of how to convert these strunctures into a raw message (bytes).
Here is for example a ClientHello message.
Can anyone share some tips or workarounds, or at least an example of how the ClientHello message should look in bytes?
I tried to sniff it out using WireShark, but it does not show the whole picture.
If something is in full .NET Framework, and does not present in Silverlight, the first option for you is to go to Mono code base and find a way to port it,
https://github.com/mono/mono
As most Mono class library code is licensed under MIT/X11, it is safe to reuse them.
Starting from scratch like you did is not recommended if you've never done similar things before.
TLS is not a trivial thing to implement. Unless you have specific reasons to do this, it's wiser to use existing implementation. You can use Mono as suggested above and port its code, or you can use SSL/TLS classes of our SecureBlackbox library, which is available for Silverlight as well, and doesn't require any extra coding from you.

monitor internet usage in .net

I want to write a method in C# to check which applications in my machine/server are using internet connection at a particular point in time and if possible, how much bandwidth they are using. Can anyone please help me get a head start on this?
I decided to write an answer because comments are too small.
Well, reading other Q&A on stackoverflow and looking around on the internet, I didn't find a simple solution for your problem.
Actually, for .NET processes is really simple, you just need to retrieve informations from ".NET CLR Networking - Bytes Received/Bytes Sent" performance counters, as shown in this Q&A
But in general, getting per-process used bandwidth isn't an easy work.
For example "Microsoft Network Monitor" sniffer can trace the process that generates internet packets only for TCP traffic, because probably it maps IP-port pairs with processes using them (or something similar, TCP is a connected protocol so it is simpler).
Anyway if you want to give it a try you can use the exposed API (look at this blog entry for some hint).
However, as suggested in these Q&A's (LINK 1, LINK 2), the right, and probably the only way, is to write a NDIS/TDI driver that can intercept network traffic and exposing a .NET callable API to it.
The problem is that such drivers can't be written in managed code, and so you need to implement it in C/C++.
Obviously, if you manage to find an already written driver/sniffer exposing a callable API, you can use it.
For example WinPCap has one (and some .NET wrappers like SharpPCap or PCap.Net), but I don't think (not sure) it's able to get packets's source-process information.
As digEmAll noted, in pre-Vista Windows you are reduced to writing your own driver or using a 3-rd party one. In Vista, 2008 and Windows 7 you can use the GetPerTcpConnectionEStats API (there is a large example of its usage on the MSDN page). Resource Monitor relies on this API, together with the older GetTcpTable/GetTcpRow APIs, for extended network statistics.
I found Process Monitor as a very useful tool and it served my purpose so I didnt had to write any code although i am yet to check out whether it gives any API which i can use in my application to get some information I need.
Thanks everyone for helping me out.

C#/.NET wrapper for serial port WIN32 Comm API

I am looking for a way to have as much control as it is possible over serial port in my c# application. The problem is that I need to communicate with a device that has no documentation except for an old c++ program written to control it. I've tried to use SerialPort class to communicate with the device but its behaviour is quite odd (I have to repeat some of the commands, some other commands dont work at all).
I would like to copy that unmanaged program's behaviour, however it seems to be impossible with serialport class, as it does not provide access to low-level functions and structures like DCB for example.
Are there any low-level wrappers for serial communication available for .net? Maybe i could use reflection to manipulate serialport innacessible members at runtime?
For those suggesting to look at the .NET SerialPort class; frequent Stack Overflow answer provider on Serial related issues, Ben Voigt, provides some excellent insights on why a wrapper around WinAPI would eventually turn out to be a much better idea than using the framework provided SerialPort:
Ben Voigt on .NET SerialPort
A must read.
He also refers to a WinAPI wrapper that he might reveal in future blog posts. If that would happen, it would answer the original question.
Also, there seems to be at least one commercial solution providing the requested functionality here.
Another edit:
Some more searching online has yielded this blog post apparently from the time when there was no SerialPort class in .NET... Source code is provided showing how to wrap Win32 API for the purpose.
EDIT
Some users have pointed out that the above mentioned MSDN blog post link is dead.
The title of the linked article was:
"Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications", written by John Hind andpublished October 2002 as I can tell from another MSDN article referring to it:
Unfortunately, Microsoft seems to only serve editions of their magazine down to 2003:
FWIW, I found a half working online version elsewhere...
Unfortunetely, the SerialPort class is an incomplete wrapper. I have found the only way to gain access to the underlying DCB is through reflection.
The only other option would be to re-write SerialPort and make it complete. I have not seen any such implementation freely available (yet).
Here is an example where I used reflection to gain access to RTS_CONTROL_TOGGLE:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/45a89532-b01c-4ef8-aa46-532882cec004
The SerialPort class is a very thin wrapper around the Win32 serial port API, hard to see how another wrapper could improve your life. There are wrappers available from the .NET 1.x days, it didn't support serial ports. Here is one from MSDN magazine.
But you're just as likely to have the same problems. One way that written commands could get lost is by the device throwing away received bytes (or losing them) when it has turned off the RTS signal off. You fix that by setting the Handshake property to RequestToSend.
One way that things can go wrong with reading commands is to get the Read() call wrong. It will return an arbitrary number of bytes, as many as are available in the receive buffer. Pay attention to the return value, it tells you how many bytes were actually read. The only guarantee is that it will at least be 1 and never more than count.
The SysInternals' PortMon utility can help you troubleshoot communications, it gives you a raw view of what the device driver sees. Compare with, say, Hyperterminal or another known-good program.
Working with a serial port through PInvoke works fine. We're doing this in a Silverlight application, but it should work the same in a normal .NET app. The answer to Serial Communication with Silverlight 5 (COM port) provides a basic wrapper for a which could easily be adapted to your needs. It uses the normal WinAPI method so you get full access to all serial port functionality, like you would in a C++ application.
P.S. If you don't already, use PortMon to monitor what's happening on the line.
You may be able to copy the old C++ code into a managed C++ class, which you could then use just like any normal .NET class from your C# code. This may be the fastest way to reach your goal.

Packet capture API - Wireshark or Microsoft Network Monitor?

I am wanting to write a C# service which runs on my server and monitors network traffic and writes it to a database for analysis. I have used Wireshark, but I think that Microsoft Network Monitor may have a better C# .NET interface for programming against. Is this true?
Can you point me to some good code samples for using Microsoft Network Monitor?
Wireshark uses the pcap (or possibly winpcap) library to capture network packets. Although they are written in C/C++ there are various .net wrappers available for them including WinPcapNet, SharpPcap and Pcap.net. I haven't used any of these so I can't comment on their usability.
I'm posting this from my phone so it's an absolute pain adding links, if you go to the Wikipedia page for pcap you should find the links you need there.
I ended up using SharpPcap, it is a great utility.

IRAPIStream COM Interface in .NET

I'm trying to use the OpenNETCF RAPI class to interact with a windows mobile device using the RAPI.Invoke() method.
According to the following article:
http://blog.opennetcf.com/ncowburn/2007/07/27/HOWTORetrieveTheDeviceIDFromTheDesktop.aspx
You can do the communication in either block or stream mode. I have used block mode before, but now I need to do something a bit more complicated with a lot more data and continuous communication and therefore need to use the stream mode. Unfortunately on that article, and basically everywhere else, there is no explaination of how to use IRAPIStream in .NET I have found C/C++ documentation, but my desktop app needs to be written in C#
Does anyone know how to properly implement the IRAPIStream COM interface in .NET?
And better yet, anyone actually used RAPI.Invoke() with IRAPIStream before? Examples would be much appreciated.
Edit: Upon a closer look at the RAPI class documentation, I realized that the Invoke() method doesn't support the stream interface.... so OpenNETCF is likely out, but maybe there is still a way to do it?
I have found that generally the most performant and stable way to push/pull large amounts of data of a device over activesync is to use a socket.
Early on we used CeRapiInvoke and a stream to pull data down of the device but ditched this early on in favour of using tcp/ip over a socket.

Categories

Resources