Swin Messenger How To
In this article we will look at how to make simple Swin Messenger Client in C#. A Swin Messenger Client is an instant messaging client that can connect to any XMPP server.
Getting the Resources
The first thing that you need to do is get the files you need. Here is the Swin Messenger Library.zip or visit http://code.google.com/p/swinmessenger/downloads/list to check that it is the latest version. Once you have downloaded it extract all the files in Swin Messenger Library.zip and save to some were you will remember it.
Setting up the Project
Now you need to create a new project and add SwinMessengerLibary.dll as a reference, follow these steps:
- Create a new C# console application project in Visual Studio
- Add the SwinMessengerLibary.dll as a reference in the project, to add a references:
- Go over the Solution Explorer Window
- Expand the Project tree out until you see "References"
- Right click on "References" and select "Add Reference..."
- Select the "Browse" tab and now navigate to were you saved SwinMessengerLibary.dll
- Once you have found it click on "OK"
Setting up the first class
Now we need to add some code to "Program.cs"
- Open up Program.cs
- Add this top the top of the class
Creating a server
Now we need to create a server so we can log into it
- Add the following code to the Program.cs class in the Main method
- "server" is the server that you wish to login to
- "account" is the account that you have on the server
- "password" is the password for the account
- Now that the server is created we can log into it. To log into a server write this
Sending your first message
Now that you have logged into the server, you will probably want to send a message.
- To send a message you need to type this
- "Contact ID" is the id of the contact you wish to send a message to
- "message" is the message you want to send to them
- The contact must be added to your roster for you to able send a message
Receiving your first message
What is the point of being able to send messages if you can't receive any messages. To receive message you need to do this
- You need to add this to Main
- This must only be called once or else you will see the same message more than once
- Now we need to create the "contact_OnMessage" event. This will need to look like this:
- This will write the any messages you receive to the screen for you to read.
Shutting down the server
Once you have sent and received all the messages you want to, you need to log out of the server. To log out of the serve you need to do this:
- Add this to the end of Main