init csharp server
This commit is contained in:
parent
cddf92e432
commit
351aad8300
|
@ -20,9 +20,13 @@
|
||||||
sqls
|
sqls
|
||||||
sql-studio
|
sql-studio
|
||||||
# Backend
|
# Backend
|
||||||
dotnetCorePackages.sdk_9_0
|
(dotnetCorePackages.combinePackages [
|
||||||
dotnetCorePackages.aspnetcore_9_0
|
dotnetCorePackages.sdk_9_0
|
||||||
|
dotnetCorePackages.aspnetcore_9_0
|
||||||
|
dotnetCorePackages.sdk_8_0
|
||||||
|
])
|
||||||
nuget
|
nuget
|
||||||
|
omnisharp-roslyn
|
||||||
|
|
||||||
# LSP
|
# LSP
|
||||||
typescript-language-server
|
typescript-language-server
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
printWidth: 100
|
||||||
|
useTabs: false
|
||||||
|
tabWidth: 2
|
||||||
|
endOfLine: auto
|
|
@ -0,0 +1,3 @@
|
||||||
|
obj
|
||||||
|
bin
|
||||||
|
|
|
@ -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");
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
|
@ -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,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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -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">
|
<script setup lang="ts">
|
||||||
import { useThemeStore } from './stores/theme';
|
import { useThemeStore } from "./stores/theme";
|
||||||
|
|
||||||
const theme = useThemeStore()
|
|
||||||
|
|
||||||
|
const theme = useThemeStore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
Loading…
Reference in New Issue