A simple multi-threaded Instant messaging program (similar to QQ,MSN)

Source: Internet
Author: User

This article implements a simple multi-threaded client/server instant Messaging application that will use a TCP connection. Allows personal messages to communicate with meetings between customers and between customers and servers. The ultimate goal is to implement instant messaging tools such as Yahoo/msn.

Library

I create a chatlibrary that contains commands and messages that can be shaded.public enum Command
{
Login = 0,
Personalmessage = 1,
Clientlist = 2,
conference = 3,
Logout = 4
};
public class Message
{
String Strsender;
String Strreceiver;
Command Cmdmessagecommand;
String Strmessagedetail;
Public message ()
{
}
Public message (Byte [] rawmessage)
{
String strrawstringmessage = System.Text.Encoding.ASCII.GetString (rawmessage);
string [] Strrawstringmessagearray = strrawstringmessage.split (new char []{' | '});
This.strsender = strrawstringmessagearray[1];
This.strreceiver = strrawstringmessagearray[2];
This.cmdmessagecommand = (Command) convert.toint32 (strrawstringmessagearray[3]);
This. Messagedetail = strrawstringmessagearray[4];
}
...
public byte [] getrawmessage ()
{
System.Text.StringBuilder sbmessage = new System.Text.StringBuilder ("John");
Sbmessage.append ("|");
Sbmessage.append (Strsender);
Sbmessage.append ("|");
Sbmessage.append (Strreceiver);
Sbmessage.append ("|");
Sbmessage.append ((int) cmdmessagecommand);
Sbmessage.append ("|");
Sbmessage.append (Strmessagedetail);
Sbmessage.append ("|");
Return System.Text.Encoding.ASCII.GetBytes (Sbmessage.tostring ());
}
...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.