Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

TCP/IP Chat Application Using C#

, 30 Jan 2006 CPOL
This is a LAN chat application with TCP/IP socket programming technology in C#. This application is a multi thread network application and works in a non-blocking way. Public and private chat is also implemented in this code.
demo.zip
Demo
ChatClient.exe
CommandClient.dll
CommandServer.dll
ConsoleServer.exe
P_0_0_0.U_0.dll
source.zip
CommandServer
CommandServer
bin
Debug
Properties
ConsoleServer
bin
Debug
obj
Debug
Refactor
ResolveAssemblyReference.cache
TempPE
Properties
CommandClient
ChatClient
bin
Debug
ChatClient.csproj.user
CSS
Graphics
arrow.gif
back.gif
face.gif
Icons
Enter.ico
Exit.ico
Private.ico
Save.ico
SendMessage.ico
Smiely.ico
Images
arrow.gif
Enter.png
Exit.png
face.gif
MNUBack.png
Private.png
Save.png
Smiely.png
Properties
Settings.settings
SoundResources
Door.wav
Knock.wav
Message.wav
Pow.wav
CommandClient
bin
Debug
obj
Debug
TempPE
Properties
P_0_0_0.U_0.dll
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace Proshot.CommandServer
{
    /// <summary>
    /// The command class.
    /// </summary>
    public class Command
    {
        private CommandType cmdType;
        /// <summary>
        /// The type of command to send.If you wanna use the Message command type,create a Message class instead of command.
        /// </summary>
        public CommandType CommandType
        {
            get { return cmdType; }
            set { cmdType = value; }
        }

        private IPAddress senderIP;
        /// <summary>
        /// [Gets/Sets] The IP address of command sender.
        /// </summary>
        public IPAddress SenderIP
        {
            get { return senderIP; }
            set { senderIP = value; }
        }

        private string senderName;
        /// <summary>
        /// [Gets/Sets] The name of command sender.
        /// </summary>
        public string SenderName
        {
            get { return senderName; }
            set { senderName = value; }
        }

        private IPAddress target;
        /// <summary>
        /// [Gets/Sets] The targer machine that will receive the command.Set this property to IPAddress.Broadcast if you want send the command to all connected clients.
        /// </summary>
        public IPAddress Target
        {
            get { return target;}
            set { target = value; }
        }
        private string commandBody;
        /// <summary>
        /// The body of the command.This string is different in various commands.
        /// <para>Message : The text of the message.</para>
        /// <para>ClientLoginInform,SendClientList : "RemoteClientIP:RemoteClientName".</para>
        /// <para>***WithTimer : The interval of timer in miliseconds..The default value is 60000 equal to 1 min.</para>
        /// <para>IsNameExists : 'True' or 'False'</para>
        /// <para>Otherwise pass the "" or null.</para>
        /// </summary>
        public string MetaData
        {
            get { return commandBody; }
            set { commandBody = value; }
        }
        /// <summary>
        /// Creates an instance of command object to send over the network.
        /// </summary>
        /// <param name="type">The type of command.If you wanna use the Message command type,create a Message class instead of command.</param>
        /// <param name="targetMachine">The targer machine that will receive the command.Set this property to IPAddress.Broadcast if you want send the command to all connected clients.</param>
        /// <param name="metaData">
        /// The body of the command.This string is different in various commands.
        /// <para>Message : The text of the message.</para>
        /// <para>ClientLoginInform,SendClientList : "RemoteClientIP:RemoteClientName".</para>
        /// <para>***WithTimer : The interval of timer in miliseconds..The default value is 60000 equal to 1 min.</para>
        /// <para>IsNameExists : 'True' or 'False'</para>
        /// <para>Otherwise pass the "" or null or use the next overriden constructor.</para>
        /// </param>
        public Command(CommandType type , IPAddress targetMachine,string metaData)
        {
            this.cmdType = type;
            this.target = targetMachine;
            this.commandBody = metaData;
        }

        /// <summary>
        /// Creates an instance of command object to send over the network.
        /// </summary>
        /// <param name="type">The type of command.If you wanna use the Message command type,create a Message class instead of command.</param>
        /// <param name="targetMachine">The targer machine that will receive the command.Set this property to IPAddress.Broadcast if you want send the command to all connected clients.</param>
        public Command(CommandType type , IPAddress targetMachine)
        {
            this.cmdType = type;
            this.target = targetMachine;
            this.commandBody = "";
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ALLEXY
Software Developer (Senior)
Australia Australia
MCPD
MCTS: ASP.NET Applications
MCTS: ADO.NET Applications
MCTS: Windows Forms Applications
MCTS: Windows Communication Foundation Applications
MCPD: Enterprise Application Developer

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 31 Jan 2006
Article Copyright 2006 by ALLEXY
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid