├── Temp.txt
├── Chat-app Client
├── Resources
│ ├── file.png
│ └── send.png
├── Program.cs
├── Chat-app Client.csproj
├── GroupCreator.cs
├── ImageView.cs
├── Login.resx
├── Signin.resx
├── GroupCreator.resx
├── ImageView.resx
├── ImageView.Designer.cs
├── Properties
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── Signin.cs
├── Login.cs
├── GroupCreator.Designer.cs
├── Login.Designer.cs
├── Signin.Designer.cs
├── ChatBox.Designer.cs
└── ChatBox.cs
├── Communicator
├── Communicator.csproj
├── Json.cs
├── Group.cs
├── Startup.cs
├── Account.cs
├── BufferFile.cs
├── Messages.cs
└── FileMessage.cs
├── Chat-app Server
├── Chat-app Server.csproj
├── Program.cs
├── Server.resx
├── Server.Designer.cs
└── Server.cs
├── README.md
├── Chat-app.sln
├── .gitattributes
└── .gitignore
/Temp.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chat-app Client/Resources/file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trinhvinhphuc/Chat-app/HEAD/Chat-app Client/Resources/file.png
--------------------------------------------------------------------------------
/Chat-app Client/Resources/send.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trinhvinhphuc/Chat-app/HEAD/Chat-app Client/Resources/send.png
--------------------------------------------------------------------------------
/Communicator/Communicator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Communicator/Json.cs:
--------------------------------------------------------------------------------
1 | namespace Communicator
2 | {
3 | public class Json
4 | {
5 | public String type { get; set; }
6 | public String content { get; set; }
7 | public Json(String type, String content)
8 | {
9 | this.type = type;
10 | this.content = content;
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/Communicator/Group.cs:
--------------------------------------------------------------------------------
1 | namespace Communicator
2 | {
3 | public class Group
4 | {
5 | public String name { get; set; }
6 | public String members { get; set; }
7 | public Group(string name, string members)
8 | {
9 | this.name = name;
10 | this.members = members;
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Communicator/Startup.cs:
--------------------------------------------------------------------------------
1 | namespace Communicator
2 | {
3 | public class Startup
4 | {
5 | public String onlUser { get; set; }
6 | public String group { get; set; }
7 | public Startup(String onlUser, String group)
8 | {
9 | this.onlUser = onlUser;
10 | this.group = group;
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Communicator/Account.cs:
--------------------------------------------------------------------------------
1 | namespace Communicator
2 | {
3 | public class Account
4 | {
5 | public string userName { get; set; }
6 | public string password { get; set; }
7 | public Account(string userName, string password)
8 | {
9 | this.userName = userName;
10 | this.password = password;
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Chat-app Server/Chat-app Server.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | net6.0-windows
6 | Chat_app_Server
7 | enable
8 | true
9 | enable
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Chat-app Client/Program.cs:
--------------------------------------------------------------------------------
1 | namespace Chat_app_Client
2 | {
3 | internal static class Program
4 | {
5 | ///
6 | /// The main entry point for the application.
7 | ///
8 | [STAThread]
9 | static void Main()
10 | {
11 | // To customize application configuration such as set high DPI settings or default font,
12 | // see https://aka.ms/applicationconfiguration.
13 | ApplicationConfiguration.Initialize();
14 | Application.Run(new Login());
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/Chat-app Server/Program.cs:
--------------------------------------------------------------------------------
1 | namespace Chat_app_Server
2 | {
3 | internal static class Program
4 | {
5 | ///
6 | /// The main entry point for the application.
7 | ///
8 | [STAThread]
9 | static void Main()
10 | {
11 | // To customize application configuration such as set high DPI settings or default font,
12 | // see https://aka.ms/applicationconfiguration.
13 | ApplicationConfiguration.Initialize();
14 | Application.Run(new Server());
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/Communicator/BufferFile.cs:
--------------------------------------------------------------------------------
1 | namespace Communicator
2 | {
3 | public class BufferFile
4 | {
5 | public String sender { get; set; }
6 | public String receiver { get; set; }
7 | public byte[] buffer { get; set; }
8 | public String extension { get; set; }
9 | public BufferFile(string sender, string receiver, byte[] buffer, string extension)
10 | {
11 | this.sender = sender;
12 | this.receiver = receiver;
13 | this.buffer = buffer;
14 | this.extension = extension;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Communicator/Messages.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Communicator
4 | {
5 | public class Messages
6 | {
7 | public String sender { get; set; }
8 | public String receiver { get; set; }
9 | public String message { get; set; }
10 | public Messages(String sender, String recerver, String message)
11 | {
12 | this.sender = sender;
13 | this.receiver = recerver;
14 | this.message = message;
15 | }
16 | [JsonConstructor]
17 | public Messages() { }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Communicator/FileMessage.cs:
--------------------------------------------------------------------------------
1 | namespace Communicator
2 | {
3 | public class FileMessage
4 | {
5 | public String sender { get; set; }
6 | public String receiver { get; set; }
7 | public String lenght { get; set; }
8 | public String extension { get; set; }
9 | public FileMessage(string sender, string receiver, string lenght, string extension)
10 | {
11 | this.sender = sender;
12 | this.receiver = receiver;
13 | this.lenght = lenght;
14 | this.extension = extension;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chat-app Client/Chat-app Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | net6.0-windows
6 | Chat_app_Client
7 | enable
8 | true
9 | enable
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | True
19 | True
20 | Resources.resx
21 |
22 |
23 |
24 |
25 |
26 | ResXFileCodeGenerator
27 | Resources.Designer.cs
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Chat-App using Socket in C#
2 | This is a simple chat application built using socket programming in C#. It allows users to connect to a server and communicate with each other via text messages.
3 |
4 | ## Requirements
5 | To run this application, you will need:
6 |
7 | - Visual Studio (2019 or later)
8 | - .NET Framework 6
9 |
10 | ## Usage
11 | To use the chat application, follow these steps:
12 |
13 | 1. Clone the repository to your local machine.
14 | 2. Open the solution file (Chat-app.sln) in Visual Studio.
15 | 3. Build the solution.
16 | 4. Start the server by running the Server project.
17 | 5. Start multiple instances of the client by running the Client project.
18 | 6. Connect to the server by entering the IP address and port number of the server in the client UI.
19 | 7. Once connected, you can send messages to other connected clients.
20 |
21 | ## Features
22 | The chat application has the following features:
23 |
24 | - Multiple clients can connect to the server and communicate with each other.
25 | - Each client can send and receive messages in real-time.
26 |
27 | ## Architecture
28 | The chat application uses a simple client-server architecture. The server listens for incoming connections on a specified port number. When a client connects, the server creates a new thread to handle the client's requests. Each client is identified by a unique ID.
29 |
30 | The communication between the client and server is done using a TCP socket. Messages are sent as byte arrays and are encoded and decoded using the UTF-8 encoding.
31 |
--------------------------------------------------------------------------------
/Chat-app Client/GroupCreator.cs:
--------------------------------------------------------------------------------
1 | using Communicator;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Data;
6 | using System.Drawing;
7 | using System.IO;
8 | using System.Linq;
9 | using System.Net.Sockets;
10 | using System.Text;
11 | using System.Text.Json;
12 | using System.Threading.Tasks;
13 | using System.Windows.Forms;
14 |
15 | namespace Chat_app_Client
16 | {
17 | public partial class GroupCreator : Form
18 | {
19 | private TcpClient server;
20 | public GroupCreator(TcpClient server)
21 | {
22 | this.server = server;
23 | InitializeComponent();
24 | }
25 |
26 | private void btnCreate_Click(object sender, EventArgs e)
27 | {
28 | if (txtGroupName.Text == "" || txtMembers.Text == "")
29 | {
30 | MessageBox.Show("Empty Fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
31 | return;
32 | }
33 | StreamWriter streamWriter = new StreamWriter(server.GetStream());
34 |
35 | Group group = new Group(txtGroupName.Text, txtMembers.Text);
36 | String jsonString = JsonSerializer.Serialize(group);
37 | Json json = new Json("CREATE_GROUP", jsonString);
38 |
39 | byte[] jsonUtf8Bytes = JsonSerializer.SerializeToUtf8Bytes(json);
40 | String S = Encoding.ASCII.GetString(jsonUtf8Bytes, 0, jsonUtf8Bytes.Length);
41 |
42 | streamWriter.WriteLine(S);
43 | streamWriter.Flush();
44 |
45 | this.Close();
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Chat-app Client/ImageView.cs:
--------------------------------------------------------------------------------
1 | using Communicator;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Data;
6 | using System.Drawing;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.Windows.Forms;
11 |
12 | namespace Chat_app_Client
13 | {
14 | public partial class ImageView : Form
15 | {
16 | private BufferFile bufferFile;
17 |
18 | public ImageView(BufferFile bufferFile)
19 | {
20 | this.bufferFile = bufferFile;
21 | InitializeComponent();
22 | this.Text = bufferFile.receiver + " - Picture from " + bufferFile.sender;
23 | }
24 |
25 | private void ImageView_Load(object sender, EventArgs e)
26 | {
27 | pictureBox1.Image = Image.FromStream(new MemoryStream(bufferFile.buffer));
28 | }
29 |
30 | private void btnCreate_Click(object sender, EventArgs e)
31 | {
32 | string fileName = @Environment.CurrentDirectory + "/" + String.Format("{0:yyyy-MM-dd HH-mm-ss}__{1}", DateTime.Now, bufferFile.sender) + bufferFile.extension;
33 | FileInfo fi = new FileInfo(fileName);
34 |
35 | try
36 | {
37 | // Check if file already exists. If yes, delete it.
38 | if (fi.Exists)
39 | {
40 | fi.Delete();
41 | }
42 |
43 | using (FileStream fStream = File.Create(fileName))
44 | {
45 | fStream.Write(bufferFile.buffer, 0, bufferFile.buffer.Length);
46 | fStream.Flush();
47 | fStream.Close();
48 | }
49 | }
50 | catch (Exception Ex)
51 | {
52 | Console.WriteLine(Ex.ToString());
53 | }
54 |
55 | this.Close();
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/Chat-app.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.3.32825.248
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chat-app Client", "Chat-app Client\Chat-app Client.csproj", "{9398E58C-5FF7-4D37-8771-D6831E3ECE84}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Communicator", "Communicator\Communicator.csproj", "{F365EE51-E430-4337-9FC1-F018B38B0B3A}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chat-app Server", "Chat-app Server\Chat-app Server.csproj", "{99D65DE9-5E8E-471E-8218-DA4364D33766}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {9398E58C-5FF7-4D37-8771-D6831E3ECE84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {9398E58C-5FF7-4D37-8771-D6831E3ECE84}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {9398E58C-5FF7-4D37-8771-D6831E3ECE84}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {9398E58C-5FF7-4D37-8771-D6831E3ECE84}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {F365EE51-E430-4337-9FC1-F018B38B0B3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {F365EE51-E430-4337-9FC1-F018B38B0B3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {F365EE51-E430-4337-9FC1-F018B38B0B3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {F365EE51-E430-4337-9FC1-F018B38B0B3A}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {99D65DE9-5E8E-471E-8218-DA4364D33766}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {99D65DE9-5E8E-471E-8218-DA4364D33766}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {99D65DE9-5E8E-471E-8218-DA4364D33766}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {99D65DE9-5E8E-471E-8218-DA4364D33766}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {A440391D-17B2-4C86-B2CD-72C28F70B2F3}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/Chat-app Client/Login.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | text/microsoft-resx
50 |
51 |
52 | 2.0
53 |
54 |
55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
56 |
57 |
58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
59 |
60 |
--------------------------------------------------------------------------------
/Chat-app Client/Signin.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | text/microsoft-resx
50 |
51 |
52 | 2.0
53 |
54 |
55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
56 |
57 |
58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
59 |
60 |
--------------------------------------------------------------------------------
/Chat-app Server/Server.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | text/microsoft-resx
50 |
51 |
52 | 2.0
53 |
54 |
55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
56 |
57 |
58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
59 |
60 |
--------------------------------------------------------------------------------
/Chat-app Client/GroupCreator.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | text/microsoft-resx
50 |
51 |
52 | 2.0
53 |
54 |
55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
56 |
57 |
58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
59 |
60 |
--------------------------------------------------------------------------------
/Chat-app Client/ImageView.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | text/microsoft-resx
50 |
51 |
52 | 2.0
53 |
54 |
55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
56 |
57 |
58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
59 |
60 |
--------------------------------------------------------------------------------
/Chat-app Client/ImageView.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Chat_app_Client
2 | {
3 | partial class ImageView
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.pictureBox1 = new System.Windows.Forms.PictureBox();
32 | this.btnCreate = new System.Windows.Forms.Button();
33 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
34 | this.SuspendLayout();
35 | //
36 | // pictureBox1
37 | //
38 | this.pictureBox1.Location = new System.Drawing.Point(12, 12);
39 | this.pictureBox1.Name = "pictureBox1";
40 | this.pictureBox1.Size = new System.Drawing.Size(413, 278);
41 | this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
42 | this.pictureBox1.TabIndex = 0;
43 | this.pictureBox1.TabStop = false;
44 | //
45 | // btnCreate
46 | //
47 | this.btnCreate.BackColor = System.Drawing.Color.RosyBrown;
48 | this.btnCreate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
49 | this.btnCreate.Font = new System.Drawing.Font("Times New Roman", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
50 | this.btnCreate.ForeColor = System.Drawing.Color.Maroon;
51 | this.btnCreate.Location = new System.Drawing.Point(128, 296);
52 | this.btnCreate.Name = "btnCreate";
53 | this.btnCreate.Size = new System.Drawing.Size(170, 27);
54 | this.btnCreate.TabIndex = 30;
55 | this.btnCreate.Text = "Download";
56 | this.btnCreate.UseVisualStyleBackColor = false;
57 | this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click);
58 | //
59 | // ImageView
60 | //
61 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
62 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
63 | this.ClientSize = new System.Drawing.Size(440, 330);
64 | this.Controls.Add(this.btnCreate);
65 | this.Controls.Add(this.pictureBox1);
66 | this.Name = "ImageView";
67 | this.Text = "Image View";
68 | this.Load += new System.EventHandler(this.ImageView_Load);
69 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
70 | this.ResumeLayout(false);
71 |
72 | }
73 |
74 | #endregion
75 |
76 | private PictureBox pictureBox1;
77 | private Button btnCreate;
78 | }
79 | }
--------------------------------------------------------------------------------
/Chat-app Client/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Chat_app_Client.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Chat_app_Client.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized resource of type System.Drawing.Bitmap.
65 | ///
66 | internal static System.Drawing.Bitmap file {
67 | get {
68 | object obj = ResourceManager.GetObject("file", resourceCulture);
69 | return ((System.Drawing.Bitmap)(obj));
70 | }
71 | }
72 |
73 | ///
74 | /// Looks up a localized resource of type System.Drawing.Bitmap.
75 | ///
76 | internal static System.Drawing.Bitmap send {
77 | get {
78 | object obj = ResourceManager.GetObject("send", resourceCulture);
79 | return ((System.Drawing.Bitmap)(obj));
80 | }
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/Chat-app Client/Signin.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Net.Sockets;
8 | using System.Net;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 | using System.Windows.Forms;
12 | using Communicator;
13 | using System.Text.Json;
14 |
15 | namespace Chat_app_Client
16 | {
17 | public partial class Signin : Form
18 | {
19 | private bool active = true;
20 | private IPEndPoint ipe;
21 | private TcpClient server;
22 | private StreamReader streamReader;
23 | private StreamWriter streamWriter;
24 |
25 | public Signin()
26 | {
27 | InitializeComponent();
28 | }
29 |
30 | private void btnSignin_Click(object sender, EventArgs e)
31 | {
32 | if (txtSigninIP.Text == "" || txtSigninPassword.Text == "" || txtSigninUsername.Text == "")
33 | {
34 | MessageBox.Show("Empty Fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
35 | return;
36 | }
37 |
38 | ipe = new IPEndPoint(IPAddress.Parse(txtSigninIP.Text), 2009);
39 | server = new TcpClient();
40 |
41 | server.Connect(ipe);
42 |
43 | streamReader = new StreamReader(server.GetStream());
44 | streamWriter = new StreamWriter(server.GetStream());
45 |
46 | var threadSign = new Thread(new ThreadStart(waitForSigninFeedback));
47 | threadSign.IsBackground = true;
48 | threadSign.Start();
49 | }
50 |
51 | private void waitForSigninFeedback()
52 | {
53 | Account account = new Account(txtSigninUsername.Text, txtSigninPassword.Text);
54 | String accountJson = JsonSerializer.Serialize(account);
55 | Json json = new Json("SIGNIN", accountJson);
56 |
57 | sendJson(json);
58 |
59 | accountJson = streamReader.ReadLine();
60 | Json? feedback = JsonSerializer.Deserialize(accountJson);
61 |
62 | try
63 | {
64 | if (feedback != null)
65 | {
66 | switch (feedback.type)
67 | {
68 | case "SIGNIN_FEEDBACK":
69 | if (feedback.content == "TRUE")
70 | {
71 | new Thread(() => Application.Run(new ChatBox(server, account.userName))).Start();
72 | this.Invoke((MethodInvoker)delegate
73 | {
74 | this.Close();
75 | });
76 | break;
77 | }
78 | if (feedback.content == "FALSE")
79 | {
80 | MessageBox.Show("Sign in failed!!", "Notification");
81 | }
82 | break;
83 | }
84 | }
85 | }
86 | catch (Exception ex)
87 | {
88 | MessageBox.Show(ex.ToString());
89 | }
90 | }
91 |
92 | private void sendJson(Json json)
93 | {
94 | byte[] jsonUtf8Bytes = JsonSerializer.SerializeToUtf8Bytes(json);
95 | String S = Encoding.ASCII.GetString(jsonUtf8Bytes, 0, jsonUtf8Bytes.Length);
96 | streamWriter.WriteLine(S);
97 | streamWriter.Flush();
98 | }
99 |
100 | private void lblSignin_Click(object sender, EventArgs e)
101 | {
102 | new Thread(() => Application.Run(new Login())).Start();
103 | this.Close();
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/Chat-app Client/Login.cs:
--------------------------------------------------------------------------------
1 | using System.Net.Sockets;
2 | using System.Net;
3 | using System.Security.Principal;
4 | using System.Text.Json;
5 | using Communicator;
6 | using System.Text;
7 | using System.Windows.Forms;
8 |
9 | namespace Chat_app_Client
10 | {
11 | public partial class Login : Form
12 | {
13 | private IPEndPoint ipe;
14 | private TcpClient server;
15 | private StreamReader streamReader;
16 | private StreamWriter streamWriter;
17 | private String name;
18 |
19 | public Login()
20 | {
21 | InitializeComponent();
22 | }
23 |
24 | private void btnLogin_Click(object sender, EventArgs e)
25 | {
26 | if (txtLoginPassword.Text == "" || txtLoginIP.Text == "" || txtLoginUsername.Text == "")
27 | {
28 | MessageBox.Show("Empty Fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
29 | return;
30 | }
31 |
32 | try
33 | {
34 | ipe = new IPEndPoint(IPAddress.Parse(txtLoginIP.Text), 2009);
35 | server = new TcpClient();
36 |
37 | server.Connect(ipe);
38 |
39 | name = txtLoginUsername.Text;
40 | streamReader = new StreamReader(server.GetStream());
41 | streamWriter = new StreamWriter(server.GetStream());
42 |
43 | var threadLog = new Thread(new ThreadStart(waitForLoginFeedback));
44 | threadLog.IsBackground = true;
45 | threadLog.Start();
46 | }
47 | catch
48 | {
49 | MessageBox.Show("Cannot connect to server", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
50 | }
51 | }
52 |
53 | private void waitForLoginFeedback()
54 | {
55 | Account account = new Account(txtLoginUsername.Text, txtLoginPassword.Text);
56 | String accountJson = JsonSerializer.Serialize(account);
57 | Json json = new Json("LOGIN", accountJson);
58 |
59 | sendJson(json, server);
60 |
61 | accountJson = streamReader.ReadLine();
62 | Json? feedback = JsonSerializer.Deserialize(accountJson);
63 |
64 | try
65 | {
66 | if (feedback != null)
67 | {
68 | switch (feedback.type)
69 | {
70 | case "LOGIN_FEEDBACK":
71 | if (feedback.content == "TRUE")
72 | {
73 | new Thread(() => Application.Run(new ChatBox(server, this.name))).Start();
74 | this.Invoke((MethodInvoker)delegate
75 | {
76 | this.Close();
77 | });
78 | break;
79 | }
80 | if (feedback.content == "FALSE")
81 | {
82 | MessageBox.Show("Login failed!!", "Notification");
83 | }
84 | break;
85 | }
86 | }
87 | }
88 | catch (Exception ex)
89 | {
90 | MessageBox.Show(ex.ToString());
91 | }
92 | }
93 |
94 | private void sendJson(Json json, TcpClient client)
95 | {
96 | byte[] jsonUtf8Bytes = JsonSerializer.SerializeToUtf8Bytes(json);
97 | StreamWriter streamWriter = new StreamWriter(client.GetStream());
98 | String S = Encoding.ASCII.GetString(jsonUtf8Bytes, 0, jsonUtf8Bytes.Length);
99 | streamWriter.WriteLine(S);
100 | streamWriter.Flush();
101 | }
102 |
103 | private void lblSignin_Click(object sender, EventArgs e)
104 | {
105 | new Thread(() => Application.Run(new Signin())).Start();
106 | this.Close();
107 | }
108 | }
109 | }
--------------------------------------------------------------------------------
/Chat-app Client/GroupCreator.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Chat_app_Client
2 | {
3 | partial class GroupCreator
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.label1 = new System.Windows.Forms.Label();
32 | this.txtGroupName = new System.Windows.Forms.TextBox();
33 | this.label2 = new System.Windows.Forms.Label();
34 | this.label3 = new System.Windows.Forms.Label();
35 | this.txtMembers = new System.Windows.Forms.TextBox();
36 | this.btnCreate = new System.Windows.Forms.Button();
37 | this.SuspendLayout();
38 | //
39 | // label1
40 | //
41 | this.label1.AutoSize = true;
42 | this.label1.Font = new System.Drawing.Font("Times New Roman", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
43 | this.label1.ForeColor = System.Drawing.Color.Maroon;
44 | this.label1.Location = new System.Drawing.Point(12, 9);
45 | this.label1.Name = "label1";
46 | this.label1.Size = new System.Drawing.Size(170, 22);
47 | this.label1.TabIndex = 3;
48 | this.label1.Text = "Create a new Group";
49 | //
50 | // txtGroupName
51 | //
52 | this.txtGroupName.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
53 | this.txtGroupName.Location = new System.Drawing.Point(12, 56);
54 | this.txtGroupName.Name = "txtGroupName";
55 | this.txtGroupName.Size = new System.Drawing.Size(170, 22);
56 | this.txtGroupName.TabIndex = 0;
57 | //
58 | // label2
59 | //
60 | this.label2.AutoSize = true;
61 | this.label2.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
62 | this.label2.Location = new System.Drawing.Point(12, 38);
63 | this.label2.Name = "label2";
64 | this.label2.Size = new System.Drawing.Size(76, 15);
65 | this.label2.TabIndex = 4;
66 | this.label2.Text = "Group Name";
67 | //
68 | // label3
69 | //
70 | this.label3.AutoSize = true;
71 | this.label3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
72 | this.label3.Location = new System.Drawing.Point(12, 82);
73 | this.label3.Name = "label3";
74 | this.label3.Size = new System.Drawing.Size(56, 15);
75 | this.label3.TabIndex = 5;
76 | this.label3.Text = "Members";
77 | //
78 | // txtMembers
79 | //
80 | this.txtMembers.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
81 | this.txtMembers.Location = new System.Drawing.Point(12, 100);
82 | this.txtMembers.Name = "txtMembers";
83 | this.txtMembers.Size = new System.Drawing.Size(170, 22);
84 | this.txtMembers.TabIndex = 1;
85 | //
86 | // btnCreate
87 | //
88 | this.btnCreate.BackColor = System.Drawing.Color.RosyBrown;
89 | this.btnCreate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
90 | this.btnCreate.Font = new System.Drawing.Font("Times New Roman", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
91 | this.btnCreate.ForeColor = System.Drawing.Color.Maroon;
92 | this.btnCreate.Location = new System.Drawing.Point(12, 140);
93 | this.btnCreate.Name = "btnCreate";
94 | this.btnCreate.Size = new System.Drawing.Size(170, 27);
95 | this.btnCreate.TabIndex = 2;
96 | this.btnCreate.Text = "Create";
97 | this.btnCreate.UseVisualStyleBackColor = false;
98 | this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click);
99 | //
100 | // GroupCreator
101 | //
102 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
103 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
104 | this.ClientSize = new System.Drawing.Size(196, 183);
105 | this.Controls.Add(this.btnCreate);
106 | this.Controls.Add(this.txtMembers);
107 | this.Controls.Add(this.label3);
108 | this.Controls.Add(this.txtGroupName);
109 | this.Controls.Add(this.label2);
110 | this.Controls.Add(this.label1);
111 | this.Name = "GroupCreator";
112 | this.Text = "Create a New Grou[";
113 | this.ResumeLayout(false);
114 | this.PerformLayout();
115 |
116 | }
117 |
118 | #endregion
119 |
120 | private Label label1;
121 | private TextBox txtGroupName;
122 | private Label label2;
123 | private Label label3;
124 | private TextBox txtMembers;
125 | private Button btnCreate;
126 | }
127 | }
--------------------------------------------------------------------------------
/Chat-app Client/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | ..\Resources\file.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
123 |
124 |
125 | ..\Resources\send.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
126 |
127 |
--------------------------------------------------------------------------------
/Chat-app Server/Server.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Chat_app_Server
2 | {
3 | partial class Server
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.label1 = new System.Windows.Forms.Label();
32 | this.label2 = new System.Windows.Forms.Label();
33 | this.txtIP = new System.Windows.Forms.TextBox();
34 | this.label3 = new System.Windows.Forms.Label();
35 | this.txtPort = new System.Windows.Forms.TextBox();
36 | this.btnStart = new System.Windows.Forms.Button();
37 | this.rtbDialog = new System.Windows.Forms.RichTextBox();
38 | this.btnStop = new System.Windows.Forms.Button();
39 | this.SuspendLayout();
40 | //
41 | // label1
42 | //
43 | this.label1.AutoSize = true;
44 | this.label1.Font = new System.Drawing.Font("Times New Roman", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
45 | this.label1.ForeColor = System.Drawing.Color.Maroon;
46 | this.label1.Location = new System.Drawing.Point(24, 20);
47 | this.label1.Name = "label1";
48 | this.label1.Size = new System.Drawing.Size(200, 31);
49 | this.label1.TabIndex = 0;
50 | this.label1.Text = "Server Chat-app";
51 | //
52 | // label2
53 | //
54 | this.label2.AutoSize = true;
55 | this.label2.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
56 | this.label2.Location = new System.Drawing.Point(12, 66);
57 | this.label2.Name = "label2";
58 | this.label2.Size = new System.Drawing.Size(65, 15);
59 | this.label2.TabIndex = 1;
60 | this.label2.Text = "IP Address";
61 | //
62 | // txtIP
63 | //
64 | this.txtIP.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
65 | this.txtIP.Location = new System.Drawing.Point(12, 84);
66 | this.txtIP.Name = "txtIP";
67 | this.txtIP.Size = new System.Drawing.Size(225, 22);
68 | this.txtIP.TabIndex = 1;
69 | //
70 | // label3
71 | //
72 | this.label3.AutoSize = true;
73 | this.label3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
74 | this.label3.Location = new System.Drawing.Point(12, 114);
75 | this.label3.Name = "label3";
76 | this.label3.Size = new System.Drawing.Size(31, 15);
77 | this.label3.TabIndex = 1;
78 | this.label3.Text = "Port";
79 | //
80 | // txtPort
81 | //
82 | this.txtPort.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
83 | this.txtPort.Location = new System.Drawing.Point(12, 132);
84 | this.txtPort.Name = "txtPort";
85 | this.txtPort.Size = new System.Drawing.Size(225, 22);
86 | this.txtPort.TabIndex = 2;
87 | //
88 | // btnStart
89 | //
90 | this.btnStart.BackColor = System.Drawing.Color.RosyBrown;
91 | this.btnStart.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
92 | this.btnStart.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
93 | this.btnStart.ForeColor = System.Drawing.Color.Maroon;
94 | this.btnStart.Location = new System.Drawing.Point(12, 171);
95 | this.btnStart.Name = "btnStart";
96 | this.btnStart.Size = new System.Drawing.Size(225, 32);
97 | this.btnStart.TabIndex = 0;
98 | this.btnStart.Text = "Start";
99 | this.btnStart.UseVisualStyleBackColor = false;
100 | this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
101 | //
102 | // rtbDialog
103 | //
104 | this.rtbDialog.Enabled = false;
105 | this.rtbDialog.Location = new System.Drawing.Point(12, 229);
106 | this.rtbDialog.Name = "rtbDialog";
107 | this.rtbDialog.Size = new System.Drawing.Size(225, 248);
108 | this.rtbDialog.TabIndex = 4;
109 | this.rtbDialog.Text = "";
110 | //
111 | // btnStop
112 | //
113 | this.btnStop.BackColor = System.Drawing.Color.Firebrick;
114 | this.btnStop.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
115 | this.btnStop.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
116 | this.btnStop.ForeColor = System.Drawing.Color.White;
117 | this.btnStop.Location = new System.Drawing.Point(12, 489);
118 | this.btnStop.Name = "btnStop";
119 | this.btnStop.Size = new System.Drawing.Size(225, 32);
120 | this.btnStop.TabIndex = 3;
121 | this.btnStop.Text = "Stop";
122 | this.btnStop.UseVisualStyleBackColor = false;
123 | this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
124 | //
125 | // Server
126 | //
127 | this.BackColor = System.Drawing.SystemColors.Control;
128 | this.ClientSize = new System.Drawing.Size(249, 533);
129 | this.Controls.Add(this.rtbDialog);
130 | this.Controls.Add(this.btnStop);
131 | this.Controls.Add(this.btnStart);
132 | this.Controls.Add(this.txtPort);
133 | this.Controls.Add(this.label3);
134 | this.Controls.Add(this.txtIP);
135 | this.Controls.Add(this.label2);
136 | this.Controls.Add(this.label1);
137 | this.Name = "Server";
138 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
139 | this.Text = "Server";
140 | this.Load += new System.EventHandler(this.Server_Load);
141 | this.ResumeLayout(false);
142 | this.PerformLayout();
143 |
144 | }
145 |
146 | #endregion
147 |
148 | private Label label1;
149 | private Label label2;
150 | private TextBox txtIP;
151 | private Label label3;
152 | private TextBox txtPort;
153 | private Button btnStart;
154 | private RichTextBox rtbDialog;
155 | private Button btnStop;
156 | }
157 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/Chat-app Server/Server.cs:
--------------------------------------------------------------------------------
1 | using Communicator;
2 | using Microsoft.VisualBasic.ApplicationServices;
3 | using System.IO;
4 | using System.Net;
5 | using System.Net.Http;
6 | using System.Net.Sockets;
7 | using System.Text;
8 | using System.Text.Json;
9 | using System.Windows.Forms;
10 | using System.Xml;
11 |
12 | namespace Chat_app_Server
13 | {
14 | public partial class Server : Form
15 | {
16 | private bool active = true;
17 | private IPEndPoint iep;
18 | private TcpListener server;
19 | private Dictionary USER;
20 | private Dictionary> GROUP;
21 | private Dictionary CLIENT;
22 |
23 | public Server()
24 | {
25 | InitializeComponent();
26 | }
27 |
28 | private void Server_Load(object sender, EventArgs e)
29 | {
30 | String IP = null;
31 | var host = Dns.GetHostByName(Dns.GetHostName());
32 | foreach (var ip in host.AddressList)
33 | {
34 | if (ip.ToString().Contains('.'))
35 | {
36 | IP = ip.ToString();
37 | }
38 | }
39 | if (IP == null)
40 | {
41 | MessageBox.Show("No network adapters with an IPv4 address in the system!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
42 | return;
43 | }
44 | txtIP.Text = IP;
45 | txtPort.Text = "2009";
46 |
47 | userInitialize();
48 | }
49 |
50 | private void userInitialize()
51 | {
52 | USER = new Dictionary();
53 | GROUP = new Dictionary>();
54 | CLIENT = new Dictionary();
55 |
56 | for (char uName = 'A'; uName <= 'Z'; uName++)
57 | {
58 | String pass = "123";
59 | USER.Add(uName.ToString(), pass);
60 | }
61 |
62 | for (int i = 0; i < 5; i++)
63 | {
64 | List groupUser = new List();
65 | for (byte j = 0; j < 3; j++)
66 | {
67 | char u = (Char)('A' + 3 * i + j);
68 | groupUser.Add(u.ToString());
69 | }
70 | if (!groupUser.Contains("A"))
71 | {
72 | groupUser.Add("A");
73 | }
74 | GROUP.Add("Group " + i.ToString(), groupUser);
75 | }
76 | }
77 |
78 | private void btnStart_Click(object sender, EventArgs e)
79 | {
80 | iep = new IPEndPoint(IPAddress.Parse(txtIP.Text), int.Parse(txtPort.Text));
81 | server = new TcpListener(iep);
82 | server.Start();
83 |
84 | Thread ServerThread = new Thread(new ThreadStart(ServerStart));
85 | ServerThread.IsBackground = true;
86 | ServerThread.Start();
87 | }
88 |
89 | private void ServerStart()
90 | {
91 | try
92 | {
93 | AppendRichTextBox("Start accept connect from client!");
94 | changeButtonEnable(btnStart, false);
95 | changeButtonEnable(btnStop, true);
96 | //Clipboard.SetText(txtIP.Text);
97 | while (active)
98 | {
99 | TcpClient client = server.AcceptTcpClient();
100 | var clientThread = new Thread(() => clientService(client));
101 | clientThread.Start();
102 | }
103 |
104 | }
105 | catch (Exception e)
106 | {
107 | MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
108 | }
109 | }
110 |
111 | private void clientService(TcpClient client)
112 | {
113 | StreamReader streamReader = new StreamReader(client.GetStream());
114 | String s = streamReader.ReadLine();
115 | Json infoJson = JsonSerializer.Deserialize(s);
116 |
117 | if (infoJson != null)
118 | {
119 | switch (infoJson.type)
120 | {
121 | case "SIGNIN":
122 | reponseSignin(infoJson, client);
123 | break;
124 | case "LOGIN":
125 | reponseLogin(infoJson, client);
126 | break;
127 | }
128 | }
129 |
130 | try
131 | {
132 | bool threadActive = true;
133 | while (threadActive && client != null)
134 | {
135 | s = streamReader.ReadLine();
136 | infoJson = JsonSerializer.Deserialize(s);
137 | if (infoJson != null && infoJson.content != null)
138 | {
139 | switch (infoJson.type)
140 | {
141 | case "MESSAGE":
142 | if (infoJson.content != null)
143 | {
144 | reponseMessage(infoJson);
145 | }
146 | break;
147 | case "CREATE_GROUP":
148 | if (infoJson.content != null)
149 | {
150 | createGroup(infoJson);
151 | }
152 | break;
153 | case "FILE":
154 | if (infoJson.content != null)
155 | {
156 | reponseFile(infoJson, client);
157 | }
158 | break;
159 | case "LOGOUT":
160 | if (infoJson.content != null)
161 | {
162 | CLIENT[infoJson.content].Close();
163 | CLIENT.Remove(infoJson.content);
164 | AppendRichTextBox(infoJson.content + " logged out.");
165 | threadActive = false;
166 |
167 | foreach (String key in CLIENT.Keys)
168 | {
169 | startupClient(CLIENT[key], key);
170 | }
171 | }
172 | break;
173 | }
174 | }
175 | }
176 | }
177 | catch
178 | {
179 | //client.Close();
180 | }
181 | }
182 |
183 | private void reponseSignin(Json infoJson, TcpClient client)
184 | {
185 | Account account = JsonSerializer.Deserialize(infoJson.content);
186 |
187 | if (account != null && account.userName != null && !USER.ContainsKey(account.userName) && !CLIENT.ContainsKey(account.userName))
188 | {
189 | Json notification = new Json("SIGNIN_FEEDBACK", "TRUE");
190 | sendJson(notification, client);
191 | AppendRichTextBox(account.userName + " signed in!");
192 |
193 | USER.Remove(account.userName);
194 | USER.Add(account.userName, account.password);
195 |
196 | CLIENT.Remove(account.userName);
197 | CLIENT.Add(account.userName, client);
198 |
199 | foreach (String key in CLIENT.Keys)
200 | {
201 | startupClient(CLIENT[key], key);
202 | }
203 | }
204 | }
205 |
206 | private void reponseLogin(Json infoJson, TcpClient client)
207 | {
208 | Account account = JsonSerializer.Deserialize(infoJson.content);
209 | if (account != null && account.userName != null && USER.ContainsKey(account.userName) && !CLIENT.ContainsKey(account.userName) && USER[account.userName] == account.password)
210 | {
211 | Json notification = new Json("LOGIN_FEEDBACK", "TRUE");
212 | sendJson(notification, client);
213 | AppendRichTextBox(account.userName + " logged in!");
214 |
215 | CLIENT.Remove(account.userName);
216 | CLIENT.Add(account.userName, client);
217 |
218 | foreach(String key in CLIENT.Keys)
219 | {
220 | startupClient(CLIENT[key], key);
221 | }
222 | }
223 | else
224 | {
225 | Json notification = new Json("LOGIN_FEEDBACK", "FALSE");
226 | sendJson(notification, client);
227 | AppendRichTextBox(account.userName + " can not login!");
228 | }
229 | }
230 |
231 | private void startupClient(TcpClient client, String name)
232 | {
233 | List onlUser = new List(CLIENT.Keys);
234 | onlUser.Remove(name);
235 |
236 | List group = new List();
237 | foreach (String key in GROUP.Keys)
238 | {
239 | if (GROUP[key].Contains(name))
240 | {
241 | group.Add(key);
242 | }
243 | }
244 |
245 | string jsonUser = JsonSerializer.Serialize>(onlUser);
246 | string jsonGroup = JsonSerializer.Serialize>(group);
247 |
248 | Startup startup = new Startup(jsonUser, jsonGroup);
249 | String startupJson = JsonSerializer.Serialize(startup);
250 | Json json = new Json("STARTUP_FEEDBACK", startupJson);
251 | sendJson(json, client);
252 | }
253 |
254 | private void reponseMessage(Json infoJson)
255 | {
256 | Messages messages = JsonSerializer.Deserialize(infoJson.content);
257 | if (messages != null && CLIENT.ContainsKey(messages.receiver))
258 | {
259 | AppendRichTextBox(messages.sender + " to " + messages.receiver + ": " + messages.message);
260 |
261 | TcpClient receiver = CLIENT[messages.receiver];
262 | sendJson(infoJson, receiver);
263 | receiver = CLIENT[messages.sender];
264 | sendJson(infoJson, receiver);
265 | }
266 | else
267 | {
268 | if (GROUP.ContainsKey(messages.receiver))
269 | {
270 | AppendRichTextBox(messages.sender + " to " + messages.receiver + ": " + messages.message);
271 | foreach (String user in GROUP[messages.receiver])
272 | {
273 | if (CLIENT.ContainsKey(user))
274 | {
275 | TcpClient receiver = CLIENT[user];
276 | sendJson(infoJson, receiver);
277 | }
278 | }
279 | }
280 | }
281 | }
282 |
283 | private void createGroup(Json infoJson)
284 | {
285 | List groupUser = new List();
286 | Group group = JsonSerializer.Deserialize(infoJson.content);
287 |
288 | string[] values = group.members.Split(',');
289 |
290 | for (int i = 0; i < values.Length; i++)
291 | {
292 | values[i] = values[i].Trim();
293 | groupUser.Add(values[i]);
294 | }
295 |
296 | GROUP.Add(group.name, groupUser);
297 |
298 | foreach (String key in CLIENT.Keys)
299 | {
300 | startupClient(CLIENT[key], key);
301 | }
302 | }
303 |
304 | private void reponseFile(Json infoJson, TcpClient client)
305 | {
306 | FileMessage fileMessage = JsonSerializer.Deserialize(infoJson.content);
307 |
308 | try
309 | {
310 |
311 | int length = Convert.ToInt32(fileMessage.lenght);
312 | byte[] buffer = new byte[length];
313 | int received = 0;
314 | int read = 0;
315 | int size = 1024;
316 | int remaining = 0;
317 |
318 | // Read bytes from the client using the length sent from the client
319 | while (received < length)
320 | {
321 | remaining = length - received;
322 | if (remaining < size)
323 | {
324 | size = remaining;
325 | }
326 |
327 | read = client.GetStream().Read(buffer, received, size);
328 | received += read;
329 | }
330 |
331 | BufferFile bufferFile = new BufferFile(fileMessage.sender, fileMessage.receiver, buffer, fileMessage.extension);
332 |
333 | String jsonString = JsonSerializer.Serialize(bufferFile);
334 | Json json = new Json("FILE", jsonString);
335 |
336 | if (CLIENT.ContainsKey(fileMessage.receiver))
337 | {
338 | TcpClient receiver = CLIENT[fileMessage.receiver];
339 | sendJson(json, receiver);
340 | }
341 |
342 | else
343 | {
344 | if (GROUP.ContainsKey(fileMessage.receiver))
345 | {
346 | foreach (String user in GROUP[fileMessage.receiver])
347 | {
348 | if (CLIENT.ContainsKey(user))
349 | {
350 | TcpClient receiver = CLIENT[user];
351 | sendJson(json, receiver);
352 | }
353 | }
354 | }
355 | }
356 | }
357 | catch (Exception Ex)
358 | {
359 | Console.WriteLine(Ex.ToString());
360 | }
361 | }
362 |
363 | private void sendJson(Json json, TcpClient client)
364 | {
365 | byte[] jsonUtf8Bytes = JsonSerializer.SerializeToUtf8Bytes(json);
366 | StreamWriter streamWriter = new StreamWriter(client.GetStream());
367 |
368 | String S = Encoding.ASCII.GetString(jsonUtf8Bytes, 0, jsonUtf8Bytes.Length);
369 |
370 | streamWriter.WriteLine(S);
371 | streamWriter.Flush();
372 | }
373 |
374 | private void AppendRichTextBox(string value)
375 | {
376 | if (InvokeRequired)
377 | {
378 | this.Invoke(new Action(AppendRichTextBox), new object[] { value });
379 | return;
380 | }
381 | rtbDialog.AppendText(value);
382 | rtbDialog.AppendText(Environment.NewLine);
383 | }
384 |
385 | private void changeButtonEnable(Button btn, bool enable)
386 | {
387 | btn.BeginInvoke(new MethodInvoker(() =>
388 | {
389 | btn.Enabled = enable;
390 | }));
391 | }
392 |
393 | private void btnStop_Click(object sender, EventArgs e)
394 | {
395 | if (CLIENT.Count() > 0)
396 | {
397 | MessageBox.Show("The server has " + CLIENT.Count + " user(s) logged in.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
398 | return;
399 | }
400 | active = false;
401 | Environment.Exit(0);
402 | }
403 | }
404 | }
--------------------------------------------------------------------------------
/Chat-app Client/Login.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Chat_app_Client
2 | {
3 | partial class Login
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.btnLogin = new System.Windows.Forms.Button();
32 | this.lblSignin = new System.Windows.Forms.Label();
33 | this.label7 = new System.Windows.Forms.Label();
34 | this.txtLoginPassword = new System.Windows.Forms.TextBox();
35 | this.label8 = new System.Windows.Forms.Label();
36 | this.txtLoginUsername = new System.Windows.Forms.TextBox();
37 | this.txtLoginIP = new System.Windows.Forms.TextBox();
38 | this.label9 = new System.Windows.Forms.Label();
39 | this.label10 = new System.Windows.Forms.Label();
40 | this.label11 = new System.Windows.Forms.Label();
41 | this.btnStart = new System.Windows.Forms.Button();
42 | this.label5 = new System.Windows.Forms.Label();
43 | this.label4 = new System.Windows.Forms.Label();
44 | this.textBox2 = new System.Windows.Forms.TextBox();
45 | this.label3 = new System.Windows.Forms.Label();
46 | this.textBox1 = new System.Windows.Forms.TextBox();
47 | this.txtIP = new System.Windows.Forms.TextBox();
48 | this.label2 = new System.Windows.Forms.Label();
49 | this.label6 = new System.Windows.Forms.Label();
50 | this.label1 = new System.Windows.Forms.Label();
51 | this.SuspendLayout();
52 | //
53 | // btnLogin
54 | //
55 | this.btnLogin.BackColor = System.Drawing.Color.RosyBrown;
56 | this.btnLogin.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
57 | this.btnLogin.Font = new System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
58 | this.btnLogin.ForeColor = System.Drawing.Color.Maroon;
59 | this.btnLogin.Location = new System.Drawing.Point(23, 352);
60 | this.btnLogin.Name = "btnLogin";
61 | this.btnLogin.Size = new System.Drawing.Size(324, 46);
62 | this.btnLogin.TabIndex = 3;
63 | this.btnLogin.Text = "Login";
64 | this.btnLogin.UseVisualStyleBackColor = false;
65 | this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
66 | //
67 | // lblSignin
68 | //
69 | this.lblSignin.AutoSize = true;
70 | this.lblSignin.Cursor = System.Windows.Forms.Cursors.Hand;
71 | this.lblSignin.Font = new System.Drawing.Font("Times New Roman", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Italic | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point);
72 | this.lblSignin.Location = new System.Drawing.Point(88, 415);
73 | this.lblSignin.Name = "lblSignin";
74 | this.lblSignin.Size = new System.Drawing.Size(195, 21);
75 | this.lblSignin.TabIndex = 4;
76 | this.lblSignin.Text = "Don’t have an account?";
77 | this.lblSignin.Click += new System.EventHandler(this.lblSignin_Click);
78 | //
79 | // label7
80 | //
81 | this.label7.AutoSize = true;
82 | this.label7.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
83 | this.label7.Location = new System.Drawing.Point(23, 260);
84 | this.label7.Name = "label7";
85 | this.label7.Size = new System.Drawing.Size(93, 23);
86 | this.label7.TabIndex = 42;
87 | this.label7.Text = "Password";
88 | //
89 | // txtLoginPassword
90 | //
91 | this.txtLoginPassword.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
92 | this.txtLoginPassword.Location = new System.Drawing.Point(23, 290);
93 | this.txtLoginPassword.Name = "txtLoginPassword";
94 | this.txtLoginPassword.Size = new System.Drawing.Size(324, 35);
95 | this.txtLoginPassword.TabIndex = 2;
96 | this.txtLoginPassword.UseSystemPasswordChar = true;
97 | //
98 | // label8
99 | //
100 | this.label8.AutoSize = true;
101 | this.label8.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
102 | this.label8.Location = new System.Drawing.Point(23, 181);
103 | this.label8.Name = "label8";
104 | this.label8.Size = new System.Drawing.Size(96, 23);
105 | this.label8.TabIndex = 43;
106 | this.label8.Text = "Username";
107 | //
108 | // txtLoginUsername
109 | //
110 | this.txtLoginUsername.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
111 | this.txtLoginUsername.Location = new System.Drawing.Point(23, 211);
112 | this.txtLoginUsername.Name = "txtLoginUsername";
113 | this.txtLoginUsername.Size = new System.Drawing.Size(324, 35);
114 | this.txtLoginUsername.TabIndex = 1;
115 | //
116 | // txtLoginIP
117 | //
118 | this.txtLoginIP.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
119 | this.txtLoginIP.Location = new System.Drawing.Point(23, 132);
120 | this.txtLoginIP.Name = "txtLoginIP";
121 | this.txtLoginIP.Size = new System.Drawing.Size(324, 35);
122 | this.txtLoginIP.TabIndex = 0;
123 | //
124 | // label9
125 | //
126 | this.label9.AutoSize = true;
127 | this.label9.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
128 | this.label9.Location = new System.Drawing.Point(23, 102);
129 | this.label9.Name = "label9";
130 | this.label9.Size = new System.Drawing.Size(89, 23);
131 | this.label9.TabIndex = 44;
132 | this.label9.Text = "Server IP";
133 | //
134 | // label10
135 | //
136 | this.label10.AutoSize = true;
137 | this.label10.Font = new System.Drawing.Font("Times New Roman", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
138 | this.label10.ForeColor = System.Drawing.Color.Maroon;
139 | this.label10.Location = new System.Drawing.Point(140, 58);
140 | this.label10.Name = "label10";
141 | this.label10.Size = new System.Drawing.Size(82, 31);
142 | this.label10.TabIndex = 39;
143 | this.label10.Text = "Login";
144 | //
145 | // label11
146 | //
147 | this.label11.AutoSize = true;
148 | this.label11.Font = new System.Drawing.Font("Times New Roman", 27.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
149 | this.label11.ForeColor = System.Drawing.Color.Maroon;
150 | this.label11.Location = new System.Drawing.Point(46, 15);
151 | this.label11.Name = "label11";
152 | this.label11.Size = new System.Drawing.Size(264, 43);
153 | this.label11.TabIndex = 40;
154 | this.label11.Text = "Client Chat-app";
155 | //
156 | // btnStart
157 | //
158 | this.btnStart.BackColor = System.Drawing.Color.RosyBrown;
159 | this.btnStart.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
160 | this.btnStart.Font = new System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
161 | this.btnStart.ForeColor = System.Drawing.Color.Maroon;
162 | this.btnStart.Location = new System.Drawing.Point(23, 356);
163 | this.btnStart.Name = "btnStart";
164 | this.btnStart.Size = new System.Drawing.Size(324, 36);
165 | this.btnStart.TabIndex = 3;
166 | this.btnStart.Text = "Start";
167 | this.btnStart.UseVisualStyleBackColor = false;
168 | //
169 | // label5
170 | //
171 | this.label5.AutoSize = true;
172 | this.label5.Font = new System.Drawing.Font("Times New Roman", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Italic | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point);
173 | this.label5.Location = new System.Drawing.Point(88, 415);
174 | this.label5.Name = "label5";
175 | this.label5.Size = new System.Drawing.Size(195, 21);
176 | this.label5.TabIndex = 31;
177 | this.label5.Text = "Don’t have an account?";
178 | //
179 | // label4
180 | //
181 | this.label4.AutoSize = true;
182 | this.label4.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
183 | this.label4.Location = new System.Drawing.Point(23, 260);
184 | this.label4.Name = "label4";
185 | this.label4.Size = new System.Drawing.Size(93, 23);
186 | this.label4.TabIndex = 32;
187 | this.label4.Text = "Password";
188 | //
189 | // textBox2
190 | //
191 | this.textBox2.Enabled = false;
192 | this.textBox2.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
193 | this.textBox2.Location = new System.Drawing.Point(23, 290);
194 | this.textBox2.Name = "textBox2";
195 | this.textBox2.Size = new System.Drawing.Size(324, 35);
196 | this.textBox2.TabIndex = 8;
197 | this.textBox2.UseSystemPasswordChar = true;
198 | //
199 | // label3
200 | //
201 | this.label3.AutoSize = true;
202 | this.label3.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
203 | this.label3.Location = new System.Drawing.Point(23, 181);
204 | this.label3.Name = "label3";
205 | this.label3.Size = new System.Drawing.Size(96, 23);
206 | this.label3.TabIndex = 33;
207 | this.label3.Text = "Username";
208 | //
209 | // textBox1
210 | //
211 | this.textBox1.Enabled = false;
212 | this.textBox1.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
213 | this.textBox1.Location = new System.Drawing.Point(23, 211);
214 | this.textBox1.Name = "textBox1";
215 | this.textBox1.Size = new System.Drawing.Size(324, 35);
216 | this.textBox1.TabIndex = 7;
217 | //
218 | // txtIP
219 | //
220 | this.txtIP.Enabled = false;
221 | this.txtIP.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
222 | this.txtIP.Location = new System.Drawing.Point(23, 132);
223 | this.txtIP.Name = "txtIP";
224 | this.txtIP.Size = new System.Drawing.Size(324, 35);
225 | this.txtIP.TabIndex = 6;
226 | //
227 | // label2
228 | //
229 | this.label2.AutoSize = true;
230 | this.label2.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
231 | this.label2.Location = new System.Drawing.Point(23, 102);
232 | this.label2.Name = "label2";
233 | this.label2.Size = new System.Drawing.Size(89, 23);
234 | this.label2.TabIndex = 34;
235 | this.label2.Text = "Server IP";
236 | //
237 | // label6
238 | //
239 | this.label6.AutoSize = true;
240 | this.label6.Font = new System.Drawing.Font("Times New Roman", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
241 | this.label6.ForeColor = System.Drawing.Color.Maroon;
242 | this.label6.Location = new System.Drawing.Point(140, 58);
243 | this.label6.Name = "label6";
244 | this.label6.Size = new System.Drawing.Size(89, 31);
245 | this.label6.TabIndex = 29;
246 | this.label6.Text = "Signin";
247 | //
248 | // label1
249 | //
250 | this.label1.AutoSize = true;
251 | this.label1.Font = new System.Drawing.Font("Times New Roman", 27.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
252 | this.label1.ForeColor = System.Drawing.Color.Maroon;
253 | this.label1.Location = new System.Drawing.Point(46, 15);
254 | this.label1.Name = "label1";
255 | this.label1.Size = new System.Drawing.Size(269, 43);
256 | this.label1.TabIndex = 30;
257 | this.label1.Text = "Server Chat-app";
258 | //
259 | // Login
260 | //
261 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
262 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
263 | this.ClientSize = new System.Drawing.Size(370, 450);
264 | this.Controls.Add(this.btnLogin);
265 | this.Controls.Add(this.lblSignin);
266 | this.Controls.Add(this.label7);
267 | this.Controls.Add(this.txtLoginPassword);
268 | this.Controls.Add(this.label8);
269 | this.Controls.Add(this.txtLoginUsername);
270 | this.Controls.Add(this.txtLoginIP);
271 | this.Controls.Add(this.label9);
272 | this.Controls.Add(this.label10);
273 | this.Controls.Add(this.label11);
274 | this.Controls.Add(this.btnStart);
275 | this.Controls.Add(this.label5);
276 | this.Controls.Add(this.label4);
277 | this.Controls.Add(this.textBox2);
278 | this.Controls.Add(this.label3);
279 | this.Controls.Add(this.textBox1);
280 | this.Controls.Add(this.txtIP);
281 | this.Controls.Add(this.label2);
282 | this.Controls.Add(this.label6);
283 | this.Controls.Add(this.label1);
284 | this.Name = "Login";
285 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
286 | this.Text = "Login";
287 | this.ResumeLayout(false);
288 | this.PerformLayout();
289 |
290 | }
291 |
292 | #endregion
293 |
294 | private Button btnLogin;
295 | private Label lblSignin;
296 | private Label label7;
297 | private TextBox txtLoginPassword;
298 | private Label label8;
299 | private TextBox txtLoginUsername;
300 | private TextBox txtLoginIP;
301 | private Label label9;
302 | private Label label10;
303 | private Label label11;
304 | private Button btnStart;
305 | private Label label5;
306 | private Label label4;
307 | private TextBox textBox2;
308 | private Label label3;
309 | private TextBox textBox1;
310 | private TextBox txtIP;
311 | private Label label2;
312 | private Label label6;
313 | private Label label1;
314 | }
315 | }
--------------------------------------------------------------------------------
/Chat-app Client/Signin.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Chat_app_Client
2 | {
3 | partial class Signin
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.btnStart = new System.Windows.Forms.Button();
32 | this.label5 = new System.Windows.Forms.Label();
33 | this.label4 = new System.Windows.Forms.Label();
34 | this.textBox2 = new System.Windows.Forms.TextBox();
35 | this.label3 = new System.Windows.Forms.Label();
36 | this.textBox1 = new System.Windows.Forms.TextBox();
37 | this.txtIP = new System.Windows.Forms.TextBox();
38 | this.label2 = new System.Windows.Forms.Label();
39 | this.label6 = new System.Windows.Forms.Label();
40 | this.label1 = new System.Windows.Forms.Label();
41 | this.btnSignin = new System.Windows.Forms.Button();
42 | this.lblSignin = new System.Windows.Forms.Label();
43 | this.label7 = new System.Windows.Forms.Label();
44 | this.txtSigninPassword = new System.Windows.Forms.TextBox();
45 | this.label8 = new System.Windows.Forms.Label();
46 | this.txtSigninUsername = new System.Windows.Forms.TextBox();
47 | this.txtSigninIP = new System.Windows.Forms.TextBox();
48 | this.label9 = new System.Windows.Forms.Label();
49 | this.label10 = new System.Windows.Forms.Label();
50 | this.label11 = new System.Windows.Forms.Label();
51 | this.SuspendLayout();
52 | //
53 | // btnStart
54 | //
55 | this.btnStart.BackColor = System.Drawing.Color.RosyBrown;
56 | this.btnStart.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
57 | this.btnStart.Font = new System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
58 | this.btnStart.ForeColor = System.Drawing.Color.Maroon;
59 | this.btnStart.Location = new System.Drawing.Point(23, 356);
60 | this.btnStart.Name = "btnStart";
61 | this.btnStart.Size = new System.Drawing.Size(324, 36);
62 | this.btnStart.TabIndex = 14;
63 | this.btnStart.Text = "Start";
64 | this.btnStart.UseVisualStyleBackColor = false;
65 | //
66 | // label5
67 | //
68 | this.label5.AutoSize = true;
69 | this.label5.Font = new System.Drawing.Font("Times New Roman", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Italic | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point);
70 | this.label5.Location = new System.Drawing.Point(88, 415);
71 | this.label5.Name = "label5";
72 | this.label5.Size = new System.Drawing.Size(195, 21);
73 | this.label5.TabIndex = 11;
74 | this.label5.Text = "Don’t have an account?";
75 | //
76 | // label4
77 | //
78 | this.label4.AutoSize = true;
79 | this.label4.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
80 | this.label4.Location = new System.Drawing.Point(23, 260);
81 | this.label4.Name = "label4";
82 | this.label4.Size = new System.Drawing.Size(93, 23);
83 | this.label4.TabIndex = 12;
84 | this.label4.Text = "Password";
85 | //
86 | // textBox2
87 | //
88 | this.textBox2.Enabled = false;
89 | this.textBox2.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
90 | this.textBox2.Location = new System.Drawing.Point(23, 290);
91 | this.textBox2.Name = "textBox2";
92 | this.textBox2.Size = new System.Drawing.Size(324, 35);
93 | this.textBox2.TabIndex = 4;
94 | this.textBox2.UseSystemPasswordChar = true;
95 | //
96 | // label3
97 | //
98 | this.label3.AutoSize = true;
99 | this.label3.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
100 | this.label3.Location = new System.Drawing.Point(23, 181);
101 | this.label3.Name = "label3";
102 | this.label3.Size = new System.Drawing.Size(96, 23);
103 | this.label3.TabIndex = 13;
104 | this.label3.Text = "Username";
105 | //
106 | // textBox1
107 | //
108 | this.textBox1.Enabled = false;
109 | this.textBox1.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
110 | this.textBox1.Location = new System.Drawing.Point(23, 211);
111 | this.textBox1.Name = "textBox1";
112 | this.textBox1.Size = new System.Drawing.Size(324, 35);
113 | this.textBox1.TabIndex = 2;
114 | //
115 | // txtIP
116 | //
117 | this.txtIP.Enabled = false;
118 | this.txtIP.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
119 | this.txtIP.Location = new System.Drawing.Point(23, 132);
120 | this.txtIP.Name = "txtIP";
121 | this.txtIP.Size = new System.Drawing.Size(324, 35);
122 | this.txtIP.TabIndex = 3;
123 | //
124 | // label2
125 | //
126 | this.label2.AutoSize = true;
127 | this.label2.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
128 | this.label2.Location = new System.Drawing.Point(23, 102);
129 | this.label2.Name = "label2";
130 | this.label2.Size = new System.Drawing.Size(89, 23);
131 | this.label2.TabIndex = 14;
132 | this.label2.Text = "Server IP";
133 | //
134 | // label6
135 | //
136 | this.label6.AutoSize = true;
137 | this.label6.Font = new System.Drawing.Font("Times New Roman", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
138 | this.label6.ForeColor = System.Drawing.Color.Maroon;
139 | this.label6.Location = new System.Drawing.Point(140, 58);
140 | this.label6.Name = "label6";
141 | this.label6.Size = new System.Drawing.Size(89, 31);
142 | this.label6.TabIndex = 9;
143 | this.label6.Text = "Signin";
144 | //
145 | // label1
146 | //
147 | this.label1.AutoSize = true;
148 | this.label1.Font = new System.Drawing.Font("Times New Roman", 27.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
149 | this.label1.ForeColor = System.Drawing.Color.Maroon;
150 | this.label1.Location = new System.Drawing.Point(46, 15);
151 | this.label1.Name = "label1";
152 | this.label1.Size = new System.Drawing.Size(269, 43);
153 | this.label1.TabIndex = 10;
154 | this.label1.Text = "Server Chat-app";
155 | //
156 | // btnSignin
157 | //
158 | this.btnSignin.BackColor = System.Drawing.Color.RosyBrown;
159 | this.btnSignin.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
160 | this.btnSignin.Font = new System.Drawing.Font("Times New Roman", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
161 | this.btnSignin.ForeColor = System.Drawing.Color.Maroon;
162 | this.btnSignin.Location = new System.Drawing.Point(23, 352);
163 | this.btnSignin.Name = "btnSignin";
164 | this.btnSignin.Size = new System.Drawing.Size(324, 46);
165 | this.btnSignin.TabIndex = 4;
166 | this.btnSignin.Text = "Signin";
167 | this.btnSignin.UseVisualStyleBackColor = false;
168 | this.btnSignin.Click += new System.EventHandler(this.btnSignin_Click);
169 | //
170 | // lblSignin
171 | //
172 | this.lblSignin.AutoSize = true;
173 | this.lblSignin.Cursor = System.Windows.Forms.Cursors.Hand;
174 | this.lblSignin.Font = new System.Drawing.Font("Times New Roman", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Italic | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point);
175 | this.lblSignin.Location = new System.Drawing.Point(88, 415);
176 | this.lblSignin.Name = "lblSignin";
177 | this.lblSignin.Size = new System.Drawing.Size(209, 21);
178 | this.lblSignin.TabIndex = 5;
179 | this.lblSignin.Text = "Already have an account?";
180 | this.lblSignin.Click += new System.EventHandler(this.lblSignin_Click);
181 | //
182 | // label7
183 | //
184 | this.label7.AutoSize = true;
185 | this.label7.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
186 | this.label7.Location = new System.Drawing.Point(23, 260);
187 | this.label7.Name = "label7";
188 | this.label7.Size = new System.Drawing.Size(93, 23);
189 | this.label7.TabIndex = 22;
190 | this.label7.Text = "Password";
191 | //
192 | // txtSigninPassword
193 | //
194 | this.txtSigninPassword.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
195 | this.txtSigninPassword.Location = new System.Drawing.Point(23, 290);
196 | this.txtSigninPassword.Name = "txtSigninPassword";
197 | this.txtSigninPassword.Size = new System.Drawing.Size(324, 35);
198 | this.txtSigninPassword.TabIndex = 3;
199 | this.txtSigninPassword.UseSystemPasswordChar = true;
200 | //
201 | // label8
202 | //
203 | this.label8.AutoSize = true;
204 | this.label8.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
205 | this.label8.Location = new System.Drawing.Point(23, 181);
206 | this.label8.Name = "label8";
207 | this.label8.Size = new System.Drawing.Size(96, 23);
208 | this.label8.TabIndex = 23;
209 | this.label8.Text = "Username";
210 | //
211 | // txtSigninUsername
212 | //
213 | this.txtSigninUsername.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
214 | this.txtSigninUsername.Location = new System.Drawing.Point(23, 211);
215 | this.txtSigninUsername.Name = "txtSigninUsername";
216 | this.txtSigninUsername.Size = new System.Drawing.Size(324, 35);
217 | this.txtSigninUsername.TabIndex = 1;
218 | //
219 | // txtSigninIP
220 | //
221 | this.txtSigninIP.Font = new System.Drawing.Font("Times New Roman", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
222 | this.txtSigninIP.Location = new System.Drawing.Point(23, 132);
223 | this.txtSigninIP.Name = "txtSigninIP";
224 | this.txtSigninIP.Size = new System.Drawing.Size(324, 35);
225 | this.txtSigninIP.TabIndex = 0;
226 | //
227 | // label9
228 | //
229 | this.label9.AutoSize = true;
230 | this.label9.Font = new System.Drawing.Font("Times New Roman", 15.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
231 | this.label9.Location = new System.Drawing.Point(23, 102);
232 | this.label9.Name = "label9";
233 | this.label9.Size = new System.Drawing.Size(89, 23);
234 | this.label9.TabIndex = 24;
235 | this.label9.Text = "Server IP";
236 | //
237 | // label10
238 | //
239 | this.label10.AutoSize = true;
240 | this.label10.Font = new System.Drawing.Font("Times New Roman", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
241 | this.label10.ForeColor = System.Drawing.Color.Maroon;
242 | this.label10.Location = new System.Drawing.Point(140, 58);
243 | this.label10.Name = "label10";
244 | this.label10.Size = new System.Drawing.Size(89, 31);
245 | this.label10.TabIndex = 19;
246 | this.label10.Text = "Signin";
247 | //
248 | // label11
249 | //
250 | this.label11.AutoSize = true;
251 | this.label11.Font = new System.Drawing.Font("Times New Roman", 27.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
252 | this.label11.ForeColor = System.Drawing.Color.Maroon;
253 | this.label11.Location = new System.Drawing.Point(46, 15);
254 | this.label11.Name = "label11";
255 | this.label11.Size = new System.Drawing.Size(264, 43);
256 | this.label11.TabIndex = 20;
257 | this.label11.Text = "Client Chat-app";
258 | //
259 | // Signin
260 | //
261 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
262 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
263 | this.ClientSize = new System.Drawing.Size(370, 450);
264 | this.Controls.Add(this.btnSignin);
265 | this.Controls.Add(this.lblSignin);
266 | this.Controls.Add(this.label7);
267 | this.Controls.Add(this.txtSigninPassword);
268 | this.Controls.Add(this.label8);
269 | this.Controls.Add(this.txtSigninUsername);
270 | this.Controls.Add(this.txtSigninIP);
271 | this.Controls.Add(this.label9);
272 | this.Controls.Add(this.label10);
273 | this.Controls.Add(this.label11);
274 | this.Controls.Add(this.btnStart);
275 | this.Controls.Add(this.label5);
276 | this.Controls.Add(this.label4);
277 | this.Controls.Add(this.textBox2);
278 | this.Controls.Add(this.label3);
279 | this.Controls.Add(this.textBox1);
280 | this.Controls.Add(this.txtIP);
281 | this.Controls.Add(this.label2);
282 | this.Controls.Add(this.label6);
283 | this.Controls.Add(this.label1);
284 | this.Name = "Signin";
285 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
286 | this.Text = "Signin";
287 | this.ResumeLayout(false);
288 | this.PerformLayout();
289 |
290 | }
291 |
292 | #endregion
293 |
294 | private Button btnStart;
295 | private Label label5;
296 | private Label label4;
297 | private TextBox textBox2;
298 | private Label label3;
299 | private TextBox textBox1;
300 | private TextBox txtIP;
301 | private Label label2;
302 | private Label label6;
303 | private Label label1;
304 | private Button btnSignin;
305 | private Label lblSignin;
306 | private Label label7;
307 | private TextBox txtSigninPassword;
308 | private Label label8;
309 | private TextBox txtSigninUsername;
310 | private TextBox txtSigninIP;
311 | private Label label9;
312 | private Label label10;
313 | private Label label11;
314 | }
315 | }
--------------------------------------------------------------------------------
/Chat-app Client/ChatBox.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Chat_app_Client
2 | {
3 | partial class ChatBox
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChatBox));
32 | this.tblUser = new System.Windows.Forms.DataGridView();
33 | this.Online = new System.Windows.Forms.DataGridViewButtonColumn();
34 | this.tblGroup = new System.Windows.Forms.DataGridView();
35 | this.Group = new System.Windows.Forms.DataGridViewButtonColumn();
36 | this.rtbDialog = new System.Windows.Forms.RichTextBox();
37 | this.btnPicture = new System.Windows.Forms.PictureBox();
38 | this.txtMessage = new System.Windows.Forms.TextBox();
39 | this.btnSend = new System.Windows.Forms.PictureBox();
40 | this.lblWelcome = new System.Windows.Forms.Label();
41 | this.txtReceiver = new System.Windows.Forms.TextBox();
42 | this.btnCreateGroup = new System.Windows.Forms.Button();
43 | this.button1 = new System.Windows.Forms.Button();
44 | this.btnLike = new System.Windows.Forms.PictureBox();
45 | this.btnLove = new System.Windows.Forms.PictureBox();
46 | this.btnLaugh = new System.Windows.Forms.PictureBox();
47 | this.btnCry = new System.Windows.Forms.PictureBox();
48 | this.btnDevil = new System.Windows.Forms.PictureBox();
49 | ((System.ComponentModel.ISupportInitialize)(this.tblUser)).BeginInit();
50 | ((System.ComponentModel.ISupportInitialize)(this.tblGroup)).BeginInit();
51 | ((System.ComponentModel.ISupportInitialize)(this.btnPicture)).BeginInit();
52 | ((System.ComponentModel.ISupportInitialize)(this.btnSend)).BeginInit();
53 | ((System.ComponentModel.ISupportInitialize)(this.btnLike)).BeginInit();
54 | ((System.ComponentModel.ISupportInitialize)(this.btnLove)).BeginInit();
55 | ((System.ComponentModel.ISupportInitialize)(this.btnLaugh)).BeginInit();
56 | ((System.ComponentModel.ISupportInitialize)(this.btnCry)).BeginInit();
57 | ((System.ComponentModel.ISupportInitialize)(this.btnDevil)).BeginInit();
58 | this.SuspendLayout();
59 | //
60 | // tblUser
61 | //
62 | this.tblUser.AllowUserToAddRows = false;
63 | this.tblUser.AllowUserToDeleteRows = false;
64 | this.tblUser.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
65 | this.tblUser.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
66 | this.Online});
67 | this.tblUser.Location = new System.Drawing.Point(12, 43);
68 | this.tblUser.Name = "tblUser";
69 | this.tblUser.ReadOnly = true;
70 | this.tblUser.RowTemplate.Height = 25;
71 | this.tblUser.Size = new System.Drawing.Size(152, 201);
72 | this.tblUser.TabIndex = 4;
73 | this.tblUser.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.tblUser_CellContentClick);
74 | //
75 | // Online
76 | //
77 | this.Online.HeaderText = "Online";
78 | this.Online.Name = "Online";
79 | this.Online.ReadOnly = true;
80 | this.Online.Resizable = System.Windows.Forms.DataGridViewTriState.False;
81 | this.Online.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
82 | this.Online.Width = 120;
83 | //
84 | // tblGroup
85 | //
86 | this.tblGroup.AllowUserToAddRows = false;
87 | this.tblGroup.AllowUserToDeleteRows = false;
88 | this.tblGroup.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
89 | this.tblGroup.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
90 | this.Group});
91 | this.tblGroup.Location = new System.Drawing.Point(12, 250);
92 | this.tblGroup.Name = "tblGroup";
93 | this.tblGroup.ReadOnly = true;
94 | this.tblGroup.RowTemplate.Height = 25;
95 | this.tblGroup.Size = new System.Drawing.Size(152, 201);
96 | this.tblGroup.TabIndex = 3;
97 | this.tblGroup.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.tblGroup_CellContentClick);
98 | //
99 | // Group
100 | //
101 | this.Group.HeaderText = "Group";
102 | this.Group.Name = "Group";
103 | this.Group.ReadOnly = true;
104 | this.Group.Resizable = System.Windows.Forms.DataGridViewTriState.False;
105 | this.Group.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
106 | this.Group.Width = 120;
107 | //
108 | // rtbDialog
109 | //
110 | this.rtbDialog.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
111 | this.rtbDialog.Location = new System.Drawing.Point(179, 43);
112 | this.rtbDialog.Name = "rtbDialog";
113 | this.rtbDialog.Size = new System.Drawing.Size(609, 372);
114 | this.rtbDialog.TabIndex = 2;
115 | this.rtbDialog.Text = "";
116 | //
117 | // btnPicture
118 | //
119 | this.btnPicture.Cursor = System.Windows.Forms.Cursors.Hand;
120 | this.btnPicture.Image = global::Chat_app_Client.Properties.Resources.file;
121 | this.btnPicture.Location = new System.Drawing.Point(179, 457);
122 | this.btnPicture.Name = "btnPicture";
123 | this.btnPicture.Size = new System.Drawing.Size(30, 30);
124 | this.btnPicture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
125 | this.btnPicture.TabIndex = 2;
126 | this.btnPicture.TabStop = false;
127 | this.btnPicture.Click += new System.EventHandler(this.btnPicture_Click);
128 | //
129 | // txtMessage
130 | //
131 | this.txtMessage.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
132 | this.txtMessage.Location = new System.Drawing.Point(215, 458);
133 | this.txtMessage.Name = "txtMessage";
134 | this.txtMessage.Size = new System.Drawing.Size(538, 29);
135 | this.txtMessage.TabIndex = 1;
136 | this.txtMessage.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtMessage_KeyPress);
137 | //
138 | // btnSend
139 | //
140 | this.btnSend.Cursor = System.Windows.Forms.Cursors.Hand;
141 | this.btnSend.Image = global::Chat_app_Client.Properties.Resources.send;
142 | this.btnSend.Location = new System.Drawing.Point(759, 457);
143 | this.btnSend.Name = "btnSend";
144 | this.btnSend.Size = new System.Drawing.Size(30, 30);
145 | this.btnSend.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
146 | this.btnSend.TabIndex = 2;
147 | this.btnSend.TabStop = false;
148 | this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
149 | //
150 | // lblWelcome
151 | //
152 | this.lblWelcome.AutoSize = true;
153 | this.lblWelcome.Font = new System.Drawing.Font("Times New Roman", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point);
154 | this.lblWelcome.ForeColor = System.Drawing.Color.Maroon;
155 | this.lblWelcome.Location = new System.Drawing.Point(12, 9);
156 | this.lblWelcome.Name = "lblWelcome";
157 | this.lblWelcome.Size = new System.Drawing.Size(106, 22);
158 | this.lblWelcome.TabIndex = 4;
159 | this.lblWelcome.Text = "Welcome, ...";
160 | //
161 | // txtReceiver
162 | //
163 | this.txtReceiver.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
164 | this.txtReceiver.Location = new System.Drawing.Point(179, 7);
165 | this.txtReceiver.Name = "txtReceiver";
166 | this.txtReceiver.Size = new System.Drawing.Size(111, 29);
167 | this.txtReceiver.TabIndex = 0;
168 | //
169 | // btnCreateGroup
170 | //
171 | this.btnCreateGroup.BackColor = System.Drawing.Color.RosyBrown;
172 | this.btnCreateGroup.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
173 | this.btnCreateGroup.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
174 | this.btnCreateGroup.ForeColor = System.Drawing.Color.Maroon;
175 | this.btnCreateGroup.Location = new System.Drawing.Point(12, 458);
176 | this.btnCreateGroup.Name = "btnCreateGroup";
177 | this.btnCreateGroup.Size = new System.Drawing.Size(152, 29);
178 | this.btnCreateGroup.TabIndex = 5;
179 | this.btnCreateGroup.Text = "Create Group";
180 | this.btnCreateGroup.UseVisualStyleBackColor = false;
181 | this.btnCreateGroup.Click += new System.EventHandler(this.btnCreateGroup_Click);
182 | //
183 | // button1
184 | //
185 | this.button1.BackColor = System.Drawing.Color.DarkRed;
186 | this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
187 | this.button1.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
188 | this.button1.ForeColor = System.Drawing.Color.LightCoral;
189 | this.button1.Location = new System.Drawing.Point(701, 6);
190 | this.button1.Name = "button1";
191 | this.button1.Size = new System.Drawing.Size(88, 29);
192 | this.button1.TabIndex = 29;
193 | this.button1.Text = "Logout";
194 | this.button1.UseVisualStyleBackColor = false;
195 | this.button1.Click += new System.EventHandler(this.button1_Click);
196 | //
197 | // btnLike
198 | //
199 | this.btnLike.Cursor = System.Windows.Forms.Cursors.Hand;
200 | this.btnLike.Image = ((System.Drawing.Image)(resources.GetObject("btnLike.Image")));
201 | this.btnLike.Location = new System.Drawing.Point(179, 421);
202 | this.btnLike.Name = "btnLike";
203 | this.btnLike.Size = new System.Drawing.Size(30, 30);
204 | this.btnLike.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
205 | this.btnLike.TabIndex = 2;
206 | this.btnLike.TabStop = false;
207 | this.btnLike.Click += new System.EventHandler(this.btnLike_Click);
208 | //
209 | // btnLove
210 | //
211 | this.btnLove.Cursor = System.Windows.Forms.Cursors.Hand;
212 | this.btnLove.Image = ((System.Drawing.Image)(resources.GetObject("btnLove.Image")));
213 | this.btnLove.Location = new System.Drawing.Point(229, 421);
214 | this.btnLove.Name = "btnLove";
215 | this.btnLove.Size = new System.Drawing.Size(30, 30);
216 | this.btnLove.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
217 | this.btnLove.TabIndex = 2;
218 | this.btnLove.TabStop = false;
219 | this.btnLove.Click += new System.EventHandler(this.btnLove_Click);
220 | //
221 | // btnLaugh
222 | //
223 | this.btnLaugh.Cursor = System.Windows.Forms.Cursors.Hand;
224 | this.btnLaugh.Image = ((System.Drawing.Image)(resources.GetObject("btnLaugh.Image")));
225 | this.btnLaugh.Location = new System.Drawing.Point(279, 421);
226 | this.btnLaugh.Name = "btnLaugh";
227 | this.btnLaugh.Size = new System.Drawing.Size(30, 30);
228 | this.btnLaugh.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
229 | this.btnLaugh.TabIndex = 2;
230 | this.btnLaugh.TabStop = false;
231 | this.btnLaugh.Click += new System.EventHandler(this.btnLaugh_Click);
232 | //
233 | // btnCry
234 | //
235 | this.btnCry.Cursor = System.Windows.Forms.Cursors.Hand;
236 | this.btnCry.Image = ((System.Drawing.Image)(resources.GetObject("btnCry.Image")));
237 | this.btnCry.Location = new System.Drawing.Point(329, 421);
238 | this.btnCry.Name = "btnCry";
239 | this.btnCry.Size = new System.Drawing.Size(30, 30);
240 | this.btnCry.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
241 | this.btnCry.TabIndex = 2;
242 | this.btnCry.TabStop = false;
243 | this.btnCry.Click += new System.EventHandler(this.btnCry_Click);
244 | //
245 | // btnDevil
246 | //
247 | this.btnDevil.Cursor = System.Windows.Forms.Cursors.Hand;
248 | this.btnDevil.Image = ((System.Drawing.Image)(resources.GetObject("btnDevil.Image")));
249 | this.btnDevil.Location = new System.Drawing.Point(379, 421);
250 | this.btnDevil.Name = "btnDevil";
251 | this.btnDevil.Size = new System.Drawing.Size(30, 30);
252 | this.btnDevil.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
253 | this.btnDevil.TabIndex = 2;
254 | this.btnDevil.TabStop = false;
255 | this.btnDevil.Click += new System.EventHandler(this.btnDevil_Click);
256 | //
257 | // ChatBox
258 | //
259 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
260 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
261 | this.ClientSize = new System.Drawing.Size(800, 497);
262 | this.Controls.Add(this.button1);
263 | this.Controls.Add(this.btnCreateGroup);
264 | this.Controls.Add(this.lblWelcome);
265 | this.Controls.Add(this.txtReceiver);
266 | this.Controls.Add(this.txtMessage);
267 | this.Controls.Add(this.btnSend);
268 | this.Controls.Add(this.btnDevil);
269 | this.Controls.Add(this.btnCry);
270 | this.Controls.Add(this.btnLaugh);
271 | this.Controls.Add(this.btnLove);
272 | this.Controls.Add(this.btnLike);
273 | this.Controls.Add(this.btnPicture);
274 | this.Controls.Add(this.rtbDialog);
275 | this.Controls.Add(this.tblGroup);
276 | this.Controls.Add(this.tblUser);
277 | this.Name = "ChatBox";
278 | this.Text = "ChatBox";
279 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ChatBox_FormClosing);
280 | this.Load += new System.EventHandler(this.ChatBox_Load);
281 | ((System.ComponentModel.ISupportInitialize)(this.tblUser)).EndInit();
282 | ((System.ComponentModel.ISupportInitialize)(this.tblGroup)).EndInit();
283 | ((System.ComponentModel.ISupportInitialize)(this.btnPicture)).EndInit();
284 | ((System.ComponentModel.ISupportInitialize)(this.btnSend)).EndInit();
285 | ((System.ComponentModel.ISupportInitialize)(this.btnLike)).EndInit();
286 | ((System.ComponentModel.ISupportInitialize)(this.btnLove)).EndInit();
287 | ((System.ComponentModel.ISupportInitialize)(this.btnLaugh)).EndInit();
288 | ((System.ComponentModel.ISupportInitialize)(this.btnCry)).EndInit();
289 | ((System.ComponentModel.ISupportInitialize)(this.btnDevil)).EndInit();
290 | this.ResumeLayout(false);
291 | this.PerformLayout();
292 |
293 | }
294 |
295 | #endregion
296 |
297 | private DataGridView tblUser;
298 | private DataGridView tblGroup;
299 | private RichTextBox rtbDialog;
300 | private PictureBox btnPicture;
301 | private TextBox txtMessage;
302 | private PictureBox btnSend;
303 | private Label lblWelcome;
304 | private TextBox txtReceiver;
305 | private Button btnCreateGroup;
306 | private Button button1;
307 | private DataGridViewButtonColumn Online;
308 | private DataGridViewButtonColumn Group;
309 | private PictureBox btnLike;
310 | private PictureBox btnLove;
311 | private PictureBox btnLaugh;
312 | private PictureBox btnCry;
313 | private PictureBox btnDevil;
314 | }
315 | }
--------------------------------------------------------------------------------
/Chat-app Client/ChatBox.cs:
--------------------------------------------------------------------------------
1 | using Communicator;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Data;
6 | using System.Drawing;
7 | using System.Formats.Asn1;
8 | using System.IO;
9 | using System.Linq;
10 | using System.Net.Http;
11 | using System.Net.Sockets;
12 | using System.Text;
13 | using System.Text.Json;
14 | using System.Threading.Tasks;
15 | using System.Windows.Forms;
16 | using System.Xml.Linq;
17 | using static System.Net.Mime.MediaTypeNames;
18 | using static System.Windows.Forms.LinkLabel;
19 | using Application = System.Windows.Forms.Application;
20 |
21 | namespace Chat_app_Client
22 | {
23 | public partial class ChatBox : Form
24 | {
25 | private TcpClient server;
26 | private String name;
27 | private bool threadActive = true;
28 | private StreamReader streamReader;
29 | private StreamWriter streamWriter;
30 |
31 | public ChatBox(TcpClient server, String name)
32 | {
33 | this.server = server;
34 | this.name = name;
35 | InitializeComponent();
36 | }
37 |
38 | private void ChatBox_Load(object sender, EventArgs e)
39 | {
40 | streamReader = new StreamReader(server.GetStream());
41 | streamWriter = new StreamWriter(server.GetStream());
42 |
43 | this.Text = "Chat app - " + name;
44 | lblWelcome.Text = "Welcome, " + name;
45 |
46 | var mainThread = new Thread(() => receiveTheard());
47 | mainThread.Start();
48 | mainThread.IsBackground = true;
49 | }
50 |
51 | private void btnSend_Click(object sender, EventArgs e)
52 | {
53 | if (txtMessage.Text == "" || txtReceiver.Text == "")
54 | {
55 | MessageBox.Show("Empty Fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
56 | return;
57 | }
58 |
59 | if (txtReceiver.Text == this.Name)
60 | {
61 | MessageBox.Show("Could not send message to yourself", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
62 | return;
63 | }
64 |
65 | Messages messages = new Messages(this.name, txtReceiver.Text, txtMessage.Text);
66 | String messageJson = JsonSerializer.Serialize(messages);
67 | Json json = new Json("MESSAGE", messageJson);
68 | sendJson(json);
69 |
70 | txtMessage.Clear();
71 | }
72 |
73 | private void txtMessage_KeyPress(object sender, KeyPressEventArgs e)
74 | {
75 | if ((int)e.KeyChar == 13)
76 | {
77 | btnSend_Click(this.btnSend, e);
78 | }
79 | }
80 |
81 | private void tblGroup_CellContentClick(object sender, DataGridViewCellEventArgs e)
82 | {
83 | txtReceiver.Text = tblGroup.Rows[e.RowIndex].Cells[0].Value.ToString();
84 | }
85 |
86 | private void tblUser_CellContentClick(object sender, DataGridViewCellEventArgs e)
87 | {
88 | txtReceiver.Text = tblUser.Rows[e.RowIndex].Cells["Online"].Value.ToString();
89 | }
90 |
91 | private void btnCreateGroup_Click(object sender, EventArgs e)
92 | {
93 | new Thread(() => Application.Run(new GroupCreator(server))).Start();
94 | }
95 |
96 | private void btnPicture_Click(object sender, EventArgs e)
97 | {
98 | if (txtReceiver.Text == "")
99 | {
100 | MessageBox.Show("Receiver field is empty", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
101 | return;
102 | }
103 |
104 | Thread dialogThread = new Thread(() =>
105 | {
106 | try
107 | {
108 | OpenFileDialog ofd = new OpenFileDialog();
109 | //ofd.Filter = "jpg files(*.jpg)|*.jpg| PNG files(*.png)|*.png| All files(*.*)|*.*";
110 | if (ofd.ShowDialog() == DialogResult.OK)
111 | {
112 | String fName = ofd.FileName;
113 | String path = "";
114 | fName = fName.Replace("\\", "/");
115 | while (fName.IndexOf("/") > -1)
116 | {
117 | path += fName.Substring(0, fName.IndexOf("/") + 1);
118 | fName = fName.Substring(fName.IndexOf("/") + 1);
119 | }
120 |
121 | FileMessage message = new FileMessage(this.name, txtReceiver.Text, File.ReadAllBytes(path + fName).Length.ToString(), Path.GetExtension(ofd.FileName));
122 |
123 | Json json = new Json("FILE", JsonSerializer.Serialize(message));
124 | sendJson(json);
125 |
126 | server.Client.SendFile(path + fName);
127 |
128 | AppendRichTextBox(this.name, message.receiver, "The file was sent.", "");
129 | }
130 | }
131 | catch (Exception)
132 | {
133 | MessageBox.Show("An Error Occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
134 | }
135 | });
136 | dialogThread.SetApartmentState(ApartmentState.STA);
137 | dialogThread.Start();
138 | dialogThread.IsBackground = true;
139 | }
140 |
141 | private void button1_Click(object sender, EventArgs e)
142 | {
143 | Json json = new Json("LOGOUT", this.name);
144 | sendJson(json);
145 | new Thread(() => Application.Run(new Login())).Start();
146 | threadActive = false;
147 | this.Close();
148 | }
149 |
150 | private void receiveTheard()
151 | {
152 | while(server != null && threadActive)
153 | {
154 | try
155 | {
156 | String jsonString = streamReader.ReadLine();
157 | Json? infoJson = JsonSerializer.Deserialize(jsonString);
158 |
159 | switch (infoJson.type)
160 | {
161 | case "STARTUP_FEEDBACK":
162 | cleanDataGridView(tblGroup);
163 | cleanDataGridView(tblUser);
164 |
165 | Startup startup = JsonSerializer.Deserialize(infoJson.content);
166 |
167 | List groups = JsonSerializer.Deserialize>(startup.group);
168 | foreach(String group in groups)
169 | {
170 | addDataInDataGridView(tblGroup, new string[] { group });
171 | }
172 |
173 | List users = JsonSerializer.Deserialize>(startup.onlUser);
174 | foreach (String user in users)
175 | {
176 | addDataInDataGridView(tblUser, new string[] { user });
177 | }
178 | break;
179 | case "MESSAGE":
180 | if (infoJson.content != null)
181 | {
182 | Messages message = JsonSerializer.Deserialize(infoJson.content);
183 | if (message != null)
184 | {
185 | if (message.sender != this.name)
186 | {
187 | AppendRichTextBox(message.sender, message.receiver, message.message, "");
188 | }
189 | else AppendRichTextBox(message.sender, message.receiver, message.message, "");
190 | }
191 | }
192 | break;
193 | case "FILE":
194 | if (infoJson.content != null)
195 | {
196 | BufferFile bufferFile = JsonSerializer.Deserialize(infoJson.content);
197 | List ImageExtensions = new List { ".JPG", ".JPEG", ".JPE", ".BMP", ".GIF", ".PNG" };
198 |
199 | if (ImageExtensions.Contains(bufferFile.extension.ToUpper()))
200 | {
201 | new Thread(()=> Application.Run(new ImageView(bufferFile))).Start() ;
202 |
203 | AppendRichTextBox(bufferFile.sender, bufferFile.receiver, "Shared the " + bufferFile.extension + " file in ", @Environment.CurrentDirectory);
204 | }
205 | else
206 | {
207 | string fileName = @Environment.CurrentDirectory + "/" + String.Format("{0:yyyy-MM-dd HH-mm-ss}__{1}", DateTime.Now, bufferFile.sender) + bufferFile.extension;
208 | FileInfo fi = new FileInfo(fileName);
209 |
210 | try
211 | {
212 | // Check if file already exists. If yes, delete it.
213 | if (fi.Exists)
214 | {
215 | fi.Delete();
216 | }
217 |
218 | using (FileStream fStream = File.Create(fileName))
219 | {
220 | fStream.Write(bufferFile.buffer, 0, bufferFile.buffer.Length);
221 | fStream.Flush();
222 | fStream.Close();
223 | }
224 | }
225 | catch (Exception Ex)
226 | {
227 | Console.WriteLine(Ex.ToString());
228 | }
229 |
230 | AppendRichTextBox(bufferFile.sender, bufferFile.receiver, "Shared the " + bufferFile.extension + " file in ", @Environment.CurrentDirectory);
231 | }
232 | }
233 | break;
234 | }
235 |
236 | }
237 | catch
238 | {
239 | threadActive = false;
240 | }
241 | }
242 | }
243 |
244 | private void AppendRichTextBox(string sender, string receiver, string message, string link)
245 | {
246 | rtbDialog.BeginInvoke(new MethodInvoker(() =>
247 | {
248 | Font currentFont = rtbDialog.SelectionFont;
249 |
250 | //Username
251 | rtbDialog.SelectionStart = rtbDialog.TextLength;
252 | rtbDialog.SelectionLength = 0;
253 | rtbDialog.SelectionColor = Color.Red;
254 | rtbDialog.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, FontStyle.Bold);
255 | rtbDialog.AppendText(sender + "<" + receiver + ">");
256 | rtbDialog.SelectionColor = rtbDialog.ForeColor;
257 |
258 | rtbDialog.AppendText(": ");
259 |
260 | //Message
261 | rtbDialog.SelectionStart = rtbDialog.TextLength;
262 | rtbDialog.SelectionLength = 0;
263 | rtbDialog.SelectionColor = Color.Green;
264 | rtbDialog.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, FontStyle.Regular);
265 | rtbDialog.AppendText(message);
266 | rtbDialog.SelectionColor = rtbDialog.ForeColor;
267 |
268 | rtbDialog.AppendText(" ");
269 |
270 | //link
271 | rtbDialog.SelectionStart = rtbDialog.TextLength;
272 | rtbDialog.SelectionLength = 0;
273 | rtbDialog.SelectionColor = Color.Blue;
274 | rtbDialog.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, FontStyle.Underline);
275 | rtbDialog.AppendText(link);
276 | rtbDialog.SelectionColor = rtbDialog.ForeColor;
277 |
278 |
279 | rtbDialog.SelectionStart = rtbDialog.GetFirstCharIndexOfCurrentLine();
280 | rtbDialog.SelectionLength = 0;
281 |
282 | if (sender == this.name)
283 | {
284 | rtbDialog.SelectionAlignment = HorizontalAlignment.Right;
285 | }
286 | else rtbDialog.SelectionAlignment = HorizontalAlignment.Left;
287 |
288 | rtbDialog.AppendText(Environment.NewLine);
289 | }));
290 | }
291 |
292 | private void cleanDataGridView(DataGridView dataGridView)
293 | {
294 | dataGridView.BeginInvoke(new MethodInvoker(() =>
295 | {
296 | dataGridView.Rows.Clear();
297 | }));
298 |
299 | }
300 |
301 | private void addDataInDataGridView(DataGridView dataGridView, String[] array)
302 | {
303 | dataGridView.Invoke(new Action(() => { dataGridView.Rows.Add(array); }));
304 | }
305 |
306 | private void sendJson(Json json)
307 | {
308 | byte[] jsonUtf8Bytes = JsonSerializer.SerializeToUtf8Bytes(json);
309 | String S = Encoding.ASCII.GetString(jsonUtf8Bytes, 0, jsonUtf8Bytes.Length);
310 |
311 | streamWriter.WriteLine(S);
312 | streamWriter.Flush();
313 | }
314 |
315 | private void btnLike_Click(object sender, EventArgs e)
316 | {
317 |
318 | if (txtReceiver.Text == "")
319 | {
320 | MessageBox.Show("Empty Fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
321 | return;
322 | }
323 |
324 | if (txtReceiver.Text == this.Name)
325 | {
326 | MessageBox.Show("Could not send message to yourself", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
327 | return;
328 | }
329 |
330 | Messages messages = new Messages(this.name, txtReceiver.Text, "👍");
331 | String messageJson = JsonSerializer.Serialize(messages);
332 | Json json = new Json("MESSAGE", messageJson);
333 | sendJson(json);
334 |
335 | txtMessage.Clear();
336 | }
337 |
338 | private void btnLove_Click(object sender, EventArgs e)
339 | {
340 | if (txtReceiver.Text == "")
341 | {
342 | MessageBox.Show("Empty Fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
343 | return;
344 | }
345 |
346 | if (txtReceiver.Text == this.Name)
347 | {
348 | MessageBox.Show("Could not send message to yourself", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
349 | return;
350 | }
351 |
352 | Messages messages = new Messages(this.name, txtReceiver.Text, "🥰");
353 | String messageJson = JsonSerializer.Serialize(messages);
354 | Json json = new Json("MESSAGE", messageJson);
355 | sendJson(json);
356 |
357 | txtMessage.Clear();
358 | }
359 |
360 | private void btnLaugh_Click(object sender, EventArgs e)
361 | {
362 | if (txtReceiver.Text == "")
363 | {
364 | MessageBox.Show("Empty Fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
365 | return;
366 | }
367 |
368 | if (txtReceiver.Text == this.Name)
369 | {
370 | MessageBox.Show("Could not send message to yourself", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
371 | return;
372 | }
373 |
374 | Messages messages = new Messages(this.name, txtReceiver.Text, "🤣");
375 | String messageJson = JsonSerializer.Serialize(messages);
376 | Json json = new Json("MESSAGE", messageJson);
377 | sendJson(json);
378 |
379 | txtMessage.Clear();
380 | }
381 |
382 | private void btnCry_Click(object sender, EventArgs e)
383 | {
384 | if (txtReceiver.Text == "")
385 | {
386 | MessageBox.Show("Empty Fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
387 | return;
388 | }
389 |
390 | if (txtReceiver.Text == this.Name)
391 | {
392 | MessageBox.Show("Could not send message to yourself", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
393 | return;
394 | }
395 |
396 | Messages messages = new Messages(this.name, txtReceiver.Text, "😭");
397 | String messageJson = JsonSerializer.Serialize(messages);
398 | Json json = new Json("MESSAGE", messageJson);
399 | sendJson(json);
400 |
401 | txtMessage.Clear();
402 | }
403 |
404 | private void btnDevil_Click(object sender, EventArgs e)
405 | {
406 | if (txtReceiver.Text == "")
407 | {
408 | MessageBox.Show("Empty Fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
409 | return;
410 | }
411 |
412 | if (txtReceiver.Text == this.Name)
413 | {
414 | MessageBox.Show("Could not send message to yourself", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
415 | return;
416 | }
417 |
418 | Messages messages = new Messages(this.name, txtReceiver.Text, "😈");
419 | String messageJson = JsonSerializer.Serialize(messages);
420 | Json json = new Json("MESSAGE", messageJson);
421 | sendJson(json);
422 |
423 | txtMessage.Clear();
424 | }
425 |
426 | private void ChatBox_FormClosing(object sender, FormClosingEventArgs e)
427 | {
428 | Json json = new Json("LOGOUT", this.name);
429 | sendJson(json);
430 | threadActive = false;
431 | }
432 | }
433 | }
434 |
--------------------------------------------------------------------------------