Skip to content

Commit

Permalink
🖥️ Implemented TCP connectionnection
Browse files Browse the repository at this point in the history
  • Loading branch information
matteopiffari committed Aug 18, 2022
1 parent 8e79e53 commit cdebb90
Show file tree
Hide file tree
Showing 29 changed files with 420 additions and 0 deletions.
88 changes: 88 additions & 0 deletions Program.cs
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);
//});
}
}
}
15 changes: 15 additions & 0 deletions Workmate-Server-Linux.csproj
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 added bin/Debug/net6.0/SuperSimpleTcp.dll
Binary file not shown.
Binary file added bin/Debug/net6.0/Workmate-Server-Linux
Binary file not shown.
41 changes: 41 additions & 0 deletions bin/Debug/net6.0/Workmate-Server-Linux.deps.json
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 added bin/Debug/net6.0/Workmate-Server-Linux.dll
Binary file not shown.
Binary file added bin/Debug/net6.0/Workmate-Server-Linux.pdb
Binary file not shown.
9 changes: 9 additions & 0 deletions bin/Debug/net6.0/Workmate-Server-Linux.runtimeconfig.json
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 added bin/Debug/net6.0/ref/Workmate-Server-Linux.dll
Binary file not shown.
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 = "")]
22 changes: 22 additions & 0 deletions obj/Debug/net6.0/Workmate-Server-Linux.AssemblyInfo.cs
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.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
889920687b0c532264415c85ee37c61a0980d8ab
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/
8 changes: 8 additions & 0 deletions obj/Debug/net6.0/Workmate-Server-Linux.GlobalUsings.g.cs
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 added obj/Debug/net6.0/Workmate-Server-Linux.assets.cache
Binary file not shown.
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bdb5b5d15a3c906cef51daabfd7c8787a7f18114
17 changes: 17 additions & 0 deletions obj/Debug/net6.0/Workmate-Server-Linux.csproj.FileListAbsolute.txt
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 added obj/Debug/net6.0/Workmate-Server-Linux.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
21906967771a143e5a00479f23f0e5f0ab84b4b6
Binary file added obj/Debug/net6.0/Workmate-Server-Linux.pdb
Binary file not shown.
Binary file added obj/Debug/net6.0/apphost
Binary file not shown.
Binary file added obj/Debug/net6.0/ref/Workmate-Server-Linux.dll
Binary file not shown.
66 changes: 66 additions & 0 deletions obj/Workmate-Server-Linux.csproj.nuget.dgspec.json
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"
}
}
}
}
}
15 changes: 15 additions & 0 deletions obj/Workmate-Server-Linux.csproj.nuget.g.props
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>
2 changes: 2 additions & 0 deletions obj/Workmate-Server-Linux.csproj.nuget.g.targets
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" />
Loading

0 comments on commit cdebb90

Please sign in to comment.