Commit 4fc4b0f2 authored by David Rothbauer's avatar David Rothbauer
Browse files

Initial commit

parents
No related merge requests found
Pipeline #2805 failed with stages
Showing with 239 additions and 0 deletions
+239 -0
File added
File added

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31025.194
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "chat_server", "chat_server\chat_server.csproj", "{E1F8E37B-AE3B-4841-9241-EEC28752EF9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E1F8E37B-AE3B-4841-9241-EEC28752EF9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1F8E37B-AE3B-4841-9241-EEC28752EF9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1F8E37B-AE3B-4841-9241-EEC28752EF9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1F8E37B-AE3B-4841-9241-EEC28752EF9F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D5C2E3C6-DF60-4890-9BA3-823433C7401B}
EndGlobalSection
EndGlobal
using System;
using System.Threading;
using System.Net.Sockets;
using System.Text;
using System.Collections;
namespace chat_server
{
class Program
{
public static Hashtable clientsList = new Hashtable();
static void Main(string[] args)
{
TcpListener serverSocket = new TcpListener(8888);
TcpClient clientSocket = default(TcpClient);
int counter = 0;
serverSocket.Start();
Console.WriteLine("Chat Server Started....");
counter = 0;
while ((true))
{
counter += 1;
clientSocket = serverSocket.AcceptTcpClient();
byte[] bytesFrom = new byte[65536];
string dataFromClient = null;
NetworkStream networkStream = clientSocket.GetStream();
networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
clientsList.Add(dataFromClient, clientSocket);
broadcast(dataFromClient + " Joined ", dataFromClient, false);
Console.WriteLine(dataFromClient + " Joined chat room ");
handleClinet client = new handleClinet();
client.startClient(clientSocket, dataFromClient, clientsList);
}
clientSocket.Close();
serverSocket.Stop();
Console.WriteLine("exit");
Console.ReadLine();
}
public static void broadcast(string msg, string uName, bool flag)
{
foreach (DictionaryEntry Item in clientsList)
{
TcpClient broadcastSocket;
broadcastSocket = (TcpClient)Item.Value;
NetworkStream broadcastStream = broadcastSocket.GetStream();
Byte[] broadcastBytes = null;
if (flag == true)
{
broadcastBytes = Encoding.ASCII.GetBytes(uName + " says : " + msg);
}
else
{
broadcastBytes = Encoding.ASCII.GetBytes(msg);
}
broadcastStream.Write(broadcastBytes, 0, broadcastBytes.Length);
broadcastStream.Flush();
}
} //end broadcast function
}//end Main class
public class handleClinet
{
TcpClient clientSocket;
string clNo;
Hashtable clientsList;
public void startClient(TcpClient inClientSocket, string clineNo, Hashtable cList)
{
this.clientSocket = inClientSocket;
this.clNo = clineNo;
this.clientsList = cList;
Thread ctThread = new Thread(doChat);
ctThread.Start();
}
private void doChat()
{
int requestCount = 0;
byte[] bytesFrom = new byte[65536];
string dataFromClient = null;
Byte[] sendBytes = null;
string serverResponse = null;
string rCount = null;
requestCount = 0;
while ((true))
{
try
{
requestCount = requestCount + 1;
NetworkStream networkStream = clientSocket.GetStream();
networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
Console.WriteLine("From client - " + clNo + " : " + dataFromClient);
rCount = Convert.ToString(requestCount);
Program.broadcast(dataFromClient, clNo, true);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}//end while
}//end doChat
} //end class handleClinet
}//end namespace
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.1",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"chat_server/1.0.0": {
"runtime": {
"chat_server.dll": {}
}
}
}
},
"libraries": {
"chat_server/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
File added
File added
File added
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\DAVID\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\DAVID\\.nuget\\packages"
]
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]
File added
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("chat_server")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("chat_server")]
[assembly: System.Reflection.AssemblyTitleAttribute("chat_server")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
b29a1da70cfae8f627d72b50ebaec50f341afbc2
File added
37c7eb91b966256c920f0072acf1a7445b88abe1
C:\Users\DAVID\source\repos\chat_server\chat_server\bin\Debug\netcoreapp3.1\chat_server.exe
C:\Users\DAVID\source\repos\chat_server\chat_server\bin\Debug\netcoreapp3.1\chat_server.deps.json
C:\Users\DAVID\source\repos\chat_server\chat_server\bin\Debug\netcoreapp3.1\chat_server.runtimeconfig.json
C:\Users\DAVID\source\repos\chat_server\chat_server\bin\Debug\netcoreapp3.1\chat_server.runtimeconfig.dev.json
C:\Users\DAVID\source\repos\chat_server\chat_server\bin\Debug\netcoreapp3.1\chat_server.dll
C:\Users\DAVID\source\repos\chat_server\chat_server\bin\Debug\netcoreapp3.1\chat_server.pdb
C:\Users\DAVID\source\repos\chat_server\chat_server\obj\Debug\netcoreapp3.1\chat_server.csprojAssemblyReference.cache
C:\Users\DAVID\source\repos\chat_server\chat_server\obj\Debug\netcoreapp3.1\chat_server.AssemblyInfoInputs.cache
C:\Users\DAVID\source\repos\chat_server\chat_server\obj\Debug\netcoreapp3.1\chat_server.AssemblyInfo.cs
C:\Users\DAVID\source\repos\chat_server\chat_server\obj\Debug\netcoreapp3.1\chat_server.csproj.CoreCompileInputs.cache
C:\Users\DAVID\source\repos\chat_server\chat_server\obj\Debug\netcoreapp3.1\chat_server.dll
C:\Users\DAVID\source\repos\chat_server\chat_server\obj\Debug\netcoreapp3.1\chat_server.pdb
C:\Users\DAVID\source\repos\chat_server\chat_server\obj\Debug\netcoreapp3.1\chat_server.genruntimeconfig.cache
File added
File added
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment