Inspired by my need to know who was calling without hauling my butt off the couch to look at the caller ID on the phone across the room (my father always said that "laziness is the mother of invention"), I built a couple of C# classes for managing an IM connection and an IM session. The test client is a console application that just sends messages and dumps whatever it gets from the IM server to the console, but I think it would serve as the code is the beginnings of a real IM client. It does the MD5 stuff properly and handles being redirected to another IM server, so the hard part of the protocol is already implemented. The sample itself is a handy little program that logs in as an IM user, sends a message to another IM user and logs back off again. Perfect for annoying your office mates. Enjoy.
Compile the VS.NET solution, update the test client app.config to reflect the passport user name and password that you'd like to login with when sending the message. Run the test client, passing in a recipient email address and message with the following command line usage (sorry I was too lazy to rename the test client : ):
usage: ConsoleApplication8.exe <imRecipientEmail> <message>
Simple usage is illustrated with the code from the test client:
void Notify(string user, string password, string who, string what) { using( ImClient im = new ImClient(user, password) ) using( ImSession session = im.RequestSession(who) ) { session.Send(what); } }
This code creates a new IM client session using a Passport user id/password pair, being careful to close the session when done with it. Then the code creates a session between the established client connection and a recipient of messages, also being careful to close the session when it's completed. Once the session is established, we send our one-shot message, close both sessions and we're done. Harry's changes how made these classes much more fully functional, as shown in his .NET messenger project.
Copyright © 2002-2004 Chris Sells
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, subject to the following restrictions: