started working o nstuff yay

This commit is contained in:
Rusty Striker 2024-12-14 17:17:58 +02:00
parent 2df8de0a3e
commit 65f5a95dac
Signed by: RustyStriker
GPG key ID: 87E4D691632DFF15
11 changed files with 295 additions and 13 deletions

View file

@ -1,2 +1,44 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using System;
using System.Net;
using System.Net.Sockets;
namespace Server;
public class Program
{
static void Main(string[] args)
{
int port = 12345;
TcpListener server = new(IPAddress.Parse("0.0.0.0"), port);
try {
server.Start();
byte[] buffer = new byte[256];
while(true) {
// Currently, every time it gets a block, it will simply send it back but ToUpper
using TcpClient client = server.AcceptTcpClient();
Console.WriteLine("Got a client!");
var stream = client.GetStream();
int readLen;
while((readLen = stream.Read(buffer, 0, buffer.Length)) != 0) {
// for now, lets just read it as an ascii string
string input = System.Text.Encoding.ASCII.GetString(buffer, 0, readLen);
Console.WriteLine($"Got block: {input}");
byte[] ret = System.Text.Encoding.ASCII.GetBytes(input.ToUpper());
stream.Write(ret, 0, ret.Length);
}
}
}
catch(Exception ex) {
Console.WriteLine($"Server error: {ex.Message}");
Console.WriteLine("Trace: " + ex.StackTrace);
}
finally {
server.Stop();
}
}
}

View file

@ -7,7 +7,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>