-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🖥️ Implemented TCP connectionnection
- Loading branch information
1 parent
8e79e53
commit cdebb90
Showing
29 changed files
with
420 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using SuperSimpleTcp; | ||
using System.Text; | ||
|
||
namespace workmateServerLinux{ | ||
public partial class Server{ | ||
|
||
SimpleTcpServer server = new SimpleTcpServer("0.0.0.0:16460"); | ||
List<string> clients = new List<string>(); | ||
public static int Main(){ | ||
bool exit=false; | ||
var program = new Server(); | ||
|
||
program.server.Events.ClientConnected += ClientConnected; | ||
program.server.Events.ClientDisconnected += ClientDisconnected; | ||
program.server.Events.DataReceived += DataReceived; | ||
|
||
program.server.Start(); | ||
Console.WriteLine("Server started"); | ||
while(!exit){ | ||
if(Console.ReadLine()=="stop") | ||
exit=true; | ||
} | ||
return 0; | ||
} | ||
private static void DataReceived(object? sender, SuperSimpleTcp.DataReceivedEventArgs e) | ||
{ | ||
var program = new Server(); | ||
/*this.Invoke((MethodInvoker)delegate | ||
{*/ | ||
Console.WriteLine($"{DateTime.Now} - {e.IpPort}: {Encoding.UTF8.GetString(e.Data)}{Environment.NewLine}"); | ||
|
||
if (Encoding.UTF8.GetString(e.Data) == "Hello, world!") | ||
{ | ||
program.server.Send($"{e.IpPort}", "Hello from server"); | ||
} | ||
else if (Encoding.UTF8.GetString(e.Data) == "Magazzino aggiornato") | ||
{ | ||
for (int i = 0; i < program.clients.Count; i++) | ||
if (program.clients[i] != e.IpPort) | ||
program.server.Send($"{program.clients[i]}", "Aggiornare magazzino"); | ||
} | ||
else if (Encoding.UTF8.GetString(e.Data) == "Prodotti aggiornati") | ||
{ | ||
for (int i = 0; i < program.clients.Count; i++) | ||
if (program.clients[i] != e.IpPort) | ||
program.server.Send($"{program.clients[i]}", "Aggiornare prodotti"); | ||
} | ||
else if (Encoding.UTF8.GetString(e.Data) == "Ordini aggiornati") | ||
{ | ||
for (int i = 0; i < program.clients.Count; i++) | ||
if (program.clients[i] != e.IpPort) | ||
program.server.Send($"{program.clients[i]}", "Aggiornare ordini"); | ||
} | ||
else if (Encoding.UTF8.GetString(e.Data) == "Clienti aggiornati") | ||
{ | ||
for (int i = 0; i < program.clients.Count; i++) | ||
if (program.clients[i] != e.IpPort) | ||
program.server.Send($"{program.clients[i]}", "Aggiornare clienti"); | ||
} | ||
else if (Encoding.UTF8.GetString(e.Data) == "Acquisti aggiornati") | ||
{ | ||
for (int i = 0; i < program.clients.Count; i++) | ||
if (program.clients[i] != e.IpPort) | ||
program.server.Send($"{program.clients[i]}", "Aggiornare acquisti"); | ||
} | ||
//}); | ||
} | ||
private static void ClientDisconnected(object? sender, SuperSimpleTcp.ConnectionEventArgs e) | ||
{ | ||
var program = new Server(); | ||
//this.Invoke((MethodInvoker)delegate | ||
//{ | ||
Console.WriteLine($"{DateTime.Now} - {e.IpPort}: Disconnesso.{Environment.NewLine}"); | ||
program.clients.Remove(e.IpPort); | ||
//}); | ||
} | ||
private static void ClientConnected(object? sender, SuperSimpleTcp.ConnectionEventArgs e) | ||
{ | ||
var program = new Server(); | ||
//this.Invoke((MethodInvoker)delegate | ||
//{ | ||
Console.WriteLine($"{DateTime.Now} - {e.IpPort}: Connesso.{Environment.NewLine}"); | ||
program.clients.Add(e.IpPort); | ||
//}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>Workmate_Server_Linux</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="SuperSimpleTcp" Version="2.6.1.4" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"runtimeTarget": { | ||
"name": ".NETCoreApp,Version=v6.0", | ||
"signature": "" | ||
}, | ||
"compilationOptions": {}, | ||
"targets": { | ||
".NETCoreApp,Version=v6.0": { | ||
"Workmate-Server-Linux/1.0.0": { | ||
"dependencies": { | ||
"SuperSimpleTcp": "2.6.1.4" | ||
}, | ||
"runtime": { | ||
"Workmate-Server-Linux.dll": {} | ||
} | ||
}, | ||
"SuperSimpleTcp/2.6.1.4": { | ||
"runtime": { | ||
"lib/net6.0/SuperSimpleTcp.dll": { | ||
"assemblyVersion": "2.6.1.4", | ||
"fileVersion": "2.6.1.4" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"libraries": { | ||
"Workmate-Server-Linux/1.0.0": { | ||
"type": "project", | ||
"serviceable": false, | ||
"sha512": "" | ||
}, | ||
"SuperSimpleTcp/2.6.1.4": { | ||
"type": "package", | ||
"serviceable": true, | ||
"sha512": "sha512-AGX5XoKGcc3jJKHkI0Tb3VxzvxEewZYowpezIWaU/QdTfN1xq2WuwdJQuvSN1F3nnIphaMWUp21sP59ZQbr/Sw==", | ||
"path": "supersimpletcp/2.6.1.4", | ||
"hashPath": "supersimpletcp.2.6.1.4.nupkg.sha512" | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"runtimeOptions": { | ||
"tfm": "net6.0", | ||
"framework": { | ||
"name": "Microsoft.NETCore.App", | ||
"version": "6.0.0" | ||
} | ||
} | ||
} |
Binary file not shown.
4 changes: 4 additions & 0 deletions
4
obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// <autogenerated /> | ||
using System; | ||
using System.Reflection; | ||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by a tool. | ||
// | ||
// 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("Workmate-Server-Linux")] | ||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] | ||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] | ||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] | ||
[assembly: System.Reflection.AssemblyProductAttribute("Workmate-Server-Linux")] | ||
[assembly: System.Reflection.AssemblyTitleAttribute("Workmate-Server-Linux")] | ||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] | ||
|
||
// Generato dalla classe WriteCodeFragment di MSBuild. | ||
|
1 change: 1 addition & 0 deletions
1
obj/Debug/net6.0/Workmate-Server-Linux.AssemblyInfoInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
889920687b0c532264415c85ee37c61a0980d8ab |
10 changes: 10 additions & 0 deletions
10
obj/Debug/net6.0/Workmate-Server-Linux.GeneratedMSBuildEditorConfig.editorconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
is_global = true | ||
build_property.TargetFramework = net6.0 | ||
build_property.TargetPlatformMinVersion = | ||
build_property.UsingMicrosoftNETSdkWeb = | ||
build_property.ProjectTypeGuids = | ||
build_property.InvariantGlobalization = | ||
build_property.PlatformNeutralAssembly = | ||
build_property._SupportedPlatformList = Linux,macOS,Windows | ||
build_property.RootNamespace = Workmate_Server_Linux | ||
build_property.ProjectDir = /home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// <auto-generated/> | ||
global using global::System; | ||
global using global::System.Collections.Generic; | ||
global using global::System.IO; | ||
global using global::System.Linq; | ||
global using global::System.Net.Http; | ||
global using global::System.Threading; | ||
global using global::System.Threading.Tasks; |
Binary file not shown.
Binary file added
BIN
+71.4 KB
obj/Debug/net6.0/Workmate-Server-Linux.csproj.AssemblyReference.cache
Binary file not shown.
Empty file.
1 change: 1 addition & 0 deletions
1
obj/Debug/net6.0/Workmate-Server-Linux.csproj.CoreCompileInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bdb5b5d15a3c906cef51daabfd7c8787a7f18114 |
17 changes: 17 additions & 0 deletions
17
obj/Debug/net6.0/Workmate-Server-Linux.csproj.FileListAbsolute.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/bin/Debug/net6.0/Workmate-Server-Linux | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/bin/Debug/net6.0/Workmate-Server-Linux.deps.json | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/bin/Debug/net6.0/Workmate-Server-Linux.runtimeconfig.json | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/bin/Debug/net6.0/Workmate-Server-Linux.dll | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/bin/Debug/net6.0/ref/Workmate-Server-Linux.dll | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/bin/Debug/net6.0/Workmate-Server-Linux.pdb | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/Debug/net6.0/Workmate-Server-Linux.csproj.AssemblyReference.cache | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/Debug/net6.0/Workmate-Server-Linux.GeneratedMSBuildEditorConfig.editorconfig | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/Debug/net6.0/Workmate-Server-Linux.AssemblyInfoInputs.cache | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/Debug/net6.0/Workmate-Server-Linux.AssemblyInfo.cs | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/Debug/net6.0/Workmate-Server-Linux.csproj.CoreCompileInputs.cache | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/Debug/net6.0/Workmate-Server-Linux.dll | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/Debug/net6.0/ref/Workmate-Server-Linux.dll | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/Debug/net6.0/Workmate-Server-Linux.pdb | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/Debug/net6.0/Workmate-Server-Linux.genruntimeconfig.cache | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/bin/Debug/net6.0/SuperSimpleTcp.dll | ||
/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/Debug/net6.0/Workmate-Server-Linux.csproj.CopyComplete |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
21906967771a143e5a00479f23f0e5f0ab84b4b6 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"format": 1, | ||
"restore": { | ||
"/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/Workmate-Server-Linux.csproj": {} | ||
}, | ||
"projects": { | ||
"/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/Workmate-Server-Linux.csproj": { | ||
"version": "1.0.0", | ||
"restore": { | ||
"projectUniqueName": "/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/Workmate-Server-Linux.csproj", | ||
"projectName": "Workmate-Server-Linux", | ||
"projectPath": "/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/Workmate-Server-Linux.csproj", | ||
"packagesPath": "/home/matteopiffari/.nuget/packages/", | ||
"outputPath": "/home/matteopiffari/Documenti/GitHub/Workmate-Server-Linux/obj/", | ||
"projectStyle": "PackageReference", | ||
"configFilePaths": [ | ||
"/home/matteopiffari/.nuget/NuGet/NuGet.Config" | ||
], | ||
"originalTargetFrameworks": [ | ||
"net6.0" | ||
], | ||
"sources": { | ||
"https://api.nuget.org/v3/index.json": {} | ||
}, | ||
"frameworks": { | ||
"net6.0": { | ||
"targetAlias": "net6.0", | ||
"projectReferences": {} | ||
} | ||
}, | ||
"warningProperties": { | ||
"warnAsError": [ | ||
"NU1605" | ||
] | ||
} | ||
}, | ||
"frameworks": { | ||
"net6.0": { | ||
"targetAlias": "net6.0", | ||
"dependencies": { | ||
"SuperSimpleTcp": { | ||
"target": "Package", | ||
"version": "[2.6.1.4, )" | ||
} | ||
}, | ||
"imports": [ | ||
"net461", | ||
"net462", | ||
"net47", | ||
"net471", | ||
"net472", | ||
"net48" | ||
], | ||
"assetTargetFallback": true, | ||
"warn": true, | ||
"frameworkReferences": { | ||
"Microsoft.NETCore.App": { | ||
"privateAssets": "all" | ||
} | ||
}, | ||
"runtimeIdentifierGraphPath": "/usr/lib/dotnet/dotnet6-6.0.108/sdk/6.0.108/RuntimeIdentifierGraph.json" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8" standalone="no"?> | ||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' "> | ||
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess> | ||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool> | ||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile> | ||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/matteopiffari/.nuget/packages/</NuGetPackageRoot> | ||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/matteopiffari/.nuget/packages/</NuGetPackageFolders> | ||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle> | ||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.0.2</NuGetToolVersion> | ||
</PropertyGroup> | ||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' "> | ||
<SourceRoot Include="/home/matteopiffari/.nuget/packages/" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8" standalone="no"?> | ||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" /> |
Oops, something went wrong.