multi thread
This commit is contained in:
15
MultiThread/Client/Client.cs
Normal file
15
MultiThread/Client/Client.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Client;
|
||||
|
||||
internal class Client
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
socket.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 20000));
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
10
MultiThread/Client/Client.csproj
Normal file
10
MultiThread/Client/Client.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
31
MultiThread/MultiThread.sln
Normal file
31
MultiThread/MultiThread.sln
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32929.385
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{CB10505E-B588-4324-AC1D-0EC7C410F8ED}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{A7321FF5-0046-4C28-BFE6-DE87E6C8E60C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{CB10505E-B588-4324-AC1D-0EC7C410F8ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CB10505E-B588-4324-AC1D-0EC7C410F8ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CB10505E-B588-4324-AC1D-0EC7C410F8ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CB10505E-B588-4324-AC1D-0EC7C410F8ED}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A7321FF5-0046-4C28-BFE6-DE87E6C8E60C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A7321FF5-0046-4C28-BFE6-DE87E6C8E60C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A7321FF5-0046-4C28-BFE6-DE87E6C8E60C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A7321FF5-0046-4C28-BFE6-DE87E6C8E60C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A8467505-FC78-4105-9BA9-C8243C6CF2FB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
10
MultiThread/MultiThread/MultiThread.csproj
Normal file
10
MultiThread/MultiThread/MultiThread.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
10
MultiThread/MultiThread/Program.cs
Normal file
10
MultiThread/MultiThread/Program.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace MultiThread
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
}
|
36
MultiThread/Server/Server.cs
Normal file
36
MultiThread/Server/Server.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Server;
|
||||
|
||||
internal class Server
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 20000);
|
||||
serverSocket.Bind(endPoint);
|
||||
serverSocket.Listen(1000);
|
||||
|
||||
while (true)
|
||||
{
|
||||
Socket clientSocket = serverSocket.Accept();
|
||||
Console.WriteLine(clientSocket.RemoteEndPoint);
|
||||
|
||||
Thread t1 = new Thread(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
byte[] buffer = new byte[256];
|
||||
int n1 = clientSocket.Receive(buffer);
|
||||
if (n1 < 1)
|
||||
{
|
||||
clientSocket.Dispose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
t1.Start();
|
||||
}
|
||||
}
|
||||
}
|
10
MultiThread/Server/Server.csproj
Normal file
10
MultiThread/Server/Server.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user