first commit

This commit is contained in:
Jose Caban
2025-06-07 11:38:03 -04:00
commit e0316ca3ff
79 changed files with 3155 additions and 0 deletions

19
TestDataServer/Program.cs Normal file
View File

@@ -0,0 +1,19 @@
using System;
namespace TestDataServer
{
class Program
{
static void Main(string[] args)
{
TestDataServer server = new TestDataServer();
server.StartListening();
//server.StopListening();
server.WaitUntilThreadsClose();
}
}
}

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace TestDataServer
{
class TestDataServer
{
private Mutex Mutex { get; set; }
private Thread Thread { get; set; }
private bool ShouldRun { get; set; }
public TestDataServer()
{
Mutex = new Mutex();
ShouldRun = false;
}
public void StartListening()
{
if (Thread == null)
{
ShouldRun = true;
Thread = new Thread(new ThreadStart(this.ListenFunction));
Thread.Start();
}
}
public void StopListening()
{
ShouldRun = false;
}
void ListenFunction()
{
Socket listenSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
int port = 2664;
// bind the listening socket to the port
IPAddress hostIP = (Dns.GetHostEntry(IPAddress.Any.ToString())).AddressList[0];
IPEndPoint ep = new IPEndPoint(hostIP, port);
listenSocket.Bind(ep);
// start listening
listenSocket.Listen(64);
while (ShouldRun)
{
Socket clientSocket = listenSocket.Accept();
ThreadPool.QueueUserWorkItem(ClientProcessingFunction, clientSocket);
}
}
void ClientProcessingFunction(object context)
{
Socket clientSocket = context as Socket;
byte[] socketBuffer = new byte[1024];
string data = null;
// Read data from client until EOF
while (true)
{
int numByte = clientSocket.Receive(socketBuffer);
data += Encoding.ASCII.GetString(socketBuffer,
0, numByte);
if (data.IndexOf("<EOF>") > -1)
break;
}
Console.WriteLine("{0}: Text received -> {1} ", Thread.ManagedThreadId, data);
byte[] message = Encoding.ASCII.GetBytes("Test Server");
clientSocket.Close();
}
public void WaitUntilThreadsClose()
{
while (Thread.IsAlive)
{
Thread.Sleep(33);
}
}
}
}

View File

@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.87
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestDataServer", "TestDataServer.csproj", "{C8E78006-51C2-4C27-AD65-F15ABD8C05DA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C8E78006-51C2-4C27-AD65-F15ABD8C05DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8E78006-51C2-4C27-AD65-F15ABD8C05DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8E78006-51C2-4C27-AD65-F15ABD8C05DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8E78006-51C2-4C27-AD65-F15ABD8C05DA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0722B7ED-F7FA-4DD6-B2E0-BDC3C59FA03A}
EndGlobalSection
EndGlobal