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
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;
using System.Net.Sockets;

namespace Proshot.CommandServer
{
    /// <summary>
    /// Occurs when a command received from a client.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">The received command object.</param>
    public delegate void CommandReceivedEventHandler(object sender,CommandEventArgs e);

    /// <summary>
    /// Occurs when a command had been sent to the remote client successfully.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">EventArgs.</param>
    public delegate void CommandSentEventHandler(object sender , EventArgs e);

    /// <summary>
    /// Occurs when a command sending action had been failed.This is because disconnection or sending exception.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">EventArgs.</param>
    public delegate void CommandSendingFailedEventHandler(object sender , EventArgs e);

    /// <summary>
    /// The class that contains information about received command.
    /// </summary>
    public class CommandEventArgs : EventArgs
    {
        private Command command;
        /// <summary>
        /// The received command.
        /// </summary>
        public Command Command
        {
            get { return command; }
        }

        /// <summary>
        /// Creates an instance of CommandEventArgs class.
        /// </summary>
        /// <param name="cmd">The received command.</param>
        public CommandEventArgs(Command cmd)
        {
            this.command = cmd;
        }
    }
    /// <summary>
    /// Occurs when a remote client had been disconnected from the server.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">The client information.</param>
    public delegate void DisconnectedEventHandler(object sender,ClientEventArgs e);
    /// <summary>
    /// Client event args.
    /// </summary>
    public class ClientEventArgs : EventArgs
    {
        private Socket socket;
        /// <summary>
        /// The ip address of remote client.
        /// </summary>
        public IPAddress IP
        {
            get { return ( (IPEndPoint)this.socket.RemoteEndPoint ).Address; }
        }
        /// <summary>
        /// The port of remote client.
        /// </summary>
        public int Port
        {
            get{return ((IPEndPoint)this.socket.RemoteEndPoint).Port;}
        }
        /// <summary>
        /// Creates an instance of ClientEventArgs class.
        /// </summary>
        /// <param name="clientManagerSocket">The socket of server side socket that comunicates with the remote client.</param>
        public ClientEventArgs(Socket clientManagerSocket)
        {
            this.socket = clientManagerSocket;
        }
    }
}

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
Web04 | 2.8.140827.1 | Last Updated 31 Jan 2006
Article Copyright 2006 by ALLEXY
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid