init csharp server
This commit is contained in:
		@@ -20,9 +20,13 @@
 | 
			
		||||
            sqls
 | 
			
		||||
            sql-studio
 | 
			
		||||
            # Backend
 | 
			
		||||
            dotnetCorePackages.sdk_9_0
 | 
			
		||||
            dotnetCorePackages.aspnetcore_9_0
 | 
			
		||||
            (dotnetCorePackages.combinePackages [
 | 
			
		||||
              dotnetCorePackages.sdk_9_0
 | 
			
		||||
              dotnetCorePackages.aspnetcore_9_0
 | 
			
		||||
              dotnetCorePackages.sdk_8_0
 | 
			
		||||
            ])
 | 
			
		||||
            nuget
 | 
			
		||||
            omnisharp-roslyn
 | 
			
		||||
 | 
			
		||||
            # LSP
 | 
			
		||||
            typescript-language-server
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								server/.csharpierrc.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								server/.csharpierrc.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
printWidth: 100
 | 
			
		||||
useTabs: false
 | 
			
		||||
tabWidth: 2
 | 
			
		||||
endOfLine: auto
 | 
			
		||||
							
								
								
									
										3
									
								
								server/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								server/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
obj
 | 
			
		||||
bin
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										43
									
								
								server/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								server/Program.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
using Microsoft.OpenApi.Models;
 | 
			
		||||
 | 
			
		||||
var builder = WebApplication.CreateBuilder(args);
 | 
			
		||||
builder.Services.AddEndpointsApiExplorer();
 | 
			
		||||
builder.Services.AddSwaggerGen(c =>
 | 
			
		||||
{
 | 
			
		||||
    c.SwaggerDoc("v1", new OpenApiInfo
 | 
			
		||||
    {
 | 
			
		||||
        Title = "FPGA Web Lab API",
 | 
			
		||||
        Description = "Use FPGA in the cloud",
 | 
			
		||||
        Version = "v1"
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
var app = builder.Build();
 | 
			
		||||
if (app.Environment.IsDevelopment())
 | 
			
		||||
{
 | 
			
		||||
    app.UseSwagger();
 | 
			
		||||
    app.UseSwaggerUI(c =>
 | 
			
		||||
    {
 | 
			
		||||
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "FPAG WebLab API V1");
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Router
 | 
			
		||||
app.MapGet("/", () => "Hello World!");
 | 
			
		||||
 | 
			
		||||
var thrdStartUdpServer = new ThreadStart(UDPServer.Start);
 | 
			
		||||
var thrdUdpServer = new Thread(thrdStartUdpServer);
 | 
			
		||||
thrdUdpServer.Start();
 | 
			
		||||
Console.WriteLine("Start UDP Server");
 | 
			
		||||
var thrdStartUdpClient = new ThreadStart(UDPClient.Start);
 | 
			
		||||
var thrdUdpClient = new Thread(thrdStartUdpClient);
 | 
			
		||||
thrdUdpClient.Start();
 | 
			
		||||
Console.WriteLine("Start UDP Client");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
thrdUdpServer.Join();
 | 
			
		||||
thrdUdpClient.Join();
 | 
			
		||||
 | 
			
		||||
// app.Run("http://localhost:5000");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										23
									
								
								server/Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								server/Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
{
 | 
			
		||||
  "$schema": "https://json.schemastore.org/launchsettings.json",
 | 
			
		||||
  "profiles": {
 | 
			
		||||
    "http": {
 | 
			
		||||
      "commandName": "Project",
 | 
			
		||||
      "dotnetRunMessages": true,
 | 
			
		||||
      "launchBrowser": true,
 | 
			
		||||
      "applicationUrl": "http://localhost:5188",
 | 
			
		||||
      "environmentVariables": {
 | 
			
		||||
        "ASPNETCORE_ENVIRONMENT": "Development"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "https": {
 | 
			
		||||
      "commandName": "Project",
 | 
			
		||||
      "dotnetRunMessages": true,
 | 
			
		||||
      "launchBrowser": true,
 | 
			
		||||
      "applicationUrl": "https://localhost:7070;http://localhost:5188",
 | 
			
		||||
      "environmentVariables": {
 | 
			
		||||
        "ASPNETCORE_ENVIRONMENT": "Development"
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								server/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								server/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
{
 | 
			
		||||
  "Logging": {
 | 
			
		||||
    "LogLevel": {
 | 
			
		||||
      "Default": "Information",
 | 
			
		||||
      "Microsoft.AspNetCore": "Warning"
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								server/appsettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								server/appsettings.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
{
 | 
			
		||||
  "Logging": {
 | 
			
		||||
    "LogLevel": {
 | 
			
		||||
      "Default": "Information",
 | 
			
		||||
      "Microsoft.AspNetCore": "Warning"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "AllowedHosts": "*"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								server/server.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								server/server.csproj
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk.Web">
 | 
			
		||||
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net9.0</TargetFramework>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
 | 
			
		||||
    <PackageReference Include="Swashbuckle.AspNetCore" Version="8.0.0" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										0
									
								
								server/src/LabProtocol.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								server/src/LabProtocol.cs
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										41
									
								
								server/src/UdpClientPool.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								server/src/UdpClientPool.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
using System.Net;
 | 
			
		||||
using System.Net.Sockets;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
class UDPClientPool
 | 
			
		||||
{
 | 
			
		||||
    private static IPAddress localhost = IPAddress.Parse("127.0.0.1");
 | 
			
		||||
 | 
			
		||||
    public UDPClientPool()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void SendLocalHost(int port, string[] stringArray)
 | 
			
		||||
    {
 | 
			
		||||
        Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
 | 
			
		||||
 | 
			
		||||
        byte[] sendbuf = Encoding.ASCII.GetBytes(stringArray[0]);
 | 
			
		||||
        IPEndPoint ep = new IPEndPoint(localhost, port);
 | 
			
		||||
 | 
			
		||||
        socket.SendTo(sendbuf, ep);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void CycleSendLocalHost(int times, int sleepMilliSeconds, int port, string[] stringArray)
 | 
			
		||||
    {
 | 
			
		||||
        Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
 | 
			
		||||
        byte[] sendbuf = Encoding.ASCII.GetBytes(stringArray[0]);
 | 
			
		||||
        IPEndPoint ep = new IPEndPoint(localhost, port);
 | 
			
		||||
 | 
			
		||||
        while (times-- >= 0)
 | 
			
		||||
        {
 | 
			
		||||
            socket.SendTo(sendbuf, ep);
 | 
			
		||||
 | 
			
		||||
            Thread.Sleep(sleepMilliSeconds);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Start()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										63
									
								
								server/src/UdpServer.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								server/src/UdpServer.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
			
		||||
using System.Net;
 | 
			
		||||
using System.Net.Sockets;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
public class UDPServer
 | 
			
		||||
{
 | 
			
		||||
    private int listenPort;
 | 
			
		||||
    private UdpClient listener;
 | 
			
		||||
    private IPEndPoint groupEP;
 | 
			
		||||
    private Thread thrd;
 | 
			
		||||
    private bool isRunning;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public UDPServer(int port)
 | 
			
		||||
    {
 | 
			
		||||
        // Construction
 | 
			
		||||
        listenPort = port;
 | 
			
		||||
        listener = new UdpClient(listenPort);
 | 
			
		||||
        groupEP = new IPEndPoint(IPAddress.Any, listenPort);
 | 
			
		||||
 | 
			
		||||
        // New Thread
 | 
			
		||||
        var thrdStart = new ThreadStart(ReceiveHandler);
 | 
			
		||||
        thrd = new Thread(thrdStart);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void ReceiveHandler()
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            while (isRunning)
 | 
			
		||||
            {
 | 
			
		||||
                byte[] bytes = listener.Receive(ref groupEP);
 | 
			
		||||
 | 
			
		||||
                Console.WriteLine($"Received broadcast from {groupEP} :");
 | 
			
		||||
                Console.WriteLine($" {Encoding.ASCII.GetString(bytes, 0, bytes.Length)}");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (SocketException e)
 | 
			
		||||
        {
 | 
			
		||||
            Console.WriteLine(e);
 | 
			
		||||
        }
 | 
			
		||||
        finally
 | 
			
		||||
        {
 | 
			
		||||
            listener.Close();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Start()
 | 
			
		||||
    {
 | 
			
		||||
        isRunning = true;
 | 
			
		||||
        thrd.Start();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Stop()
 | 
			
		||||
    {
 | 
			
		||||
        isRunning = false;
 | 
			
		||||
        thrd.Join();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -1,8 +1,7 @@
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import { useThemeStore } from './stores/theme';
 | 
			
		||||
 | 
			
		||||
const theme = useThemeStore()
 | 
			
		||||
import { useThemeStore } from "./stores/theme";
 | 
			
		||||
 | 
			
		||||
const theme = useThemeStore();
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<template>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user