Skip to content
This repository was archived by the owner on Sep 9, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Lab1_a_Client/.vs/Lab1_a_Client/v15/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions Lab1_a_Client/Lab1_a_Client.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.572
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab1_a_Client", "Lab1_a_Client\Lab1_a_Client.csproj", "{9FB83A5A-7B87-448F-A0CD-270675E13B6E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9FB83A5A-7B87-448F-A0CD-270675E13B6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9FB83A5A-7B87-448F-A0CD-270675E13B6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FB83A5A-7B87-448F-A0CD-270675E13B6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FB83A5A-7B87-448F-A0CD-270675E13B6E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {58DC775E-61F8-482B-947E-487E121C35D7}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Lab1_a_Client/Lab1_a_Client/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
117 changes: 117 additions & 0 deletions Lab1_a_Client/Lab1_a_Client/Client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class SynchronousSocketClient
{
private static string name;
private static Socket sender;

public static bool StartClient()
{
try
{
// use port 11000 on the local computer.
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress, 11000);

// Create a TCP/IP socket.
sender = new Socket(ipAddress.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
sender.Blocking = true;
try {
// Connect the socket to the remote endpoint.
sender.Connect(remoteEP);
//sender.Shutdown(SocketShutdown.Both);
//sender.Close();
}
catch (ArgumentNullException ane)
{
Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
}
catch (SocketException se)
{
Console.WriteLine("Connection Error");
Console.ReadLine();
return false;
}
catch (Exception e)
{
Console.WriteLine("Unexpected exception : {0}", e.ToString());
}
}
catch (Exception e)
{
Console.WriteLine("Connection Error");
Console.ReadLine();
return false;
}

return true;
}

private static void SendMessage(string message)
{
byte[] bytes = new byte[1024];
byte[] msg = Encoding.ASCII.GetBytes($"< {DateTime.Now.ToString("hh:mm")} > [{name}] {message}<EOF>");

int bytesSent = sender.Send(msg);
}

private static void StartReceiving()
{
ThreadStart rec = new ThreadStart(Receiving);
Thread recThread = new Thread(rec);
recThread.Start();
}

private static void Receiving()
{
while (true)
{
try
{
Thread.Sleep(100);
byte[] bytes = new byte[1024];
int bytesRec = sender.Receive(bytes);
if (bytesRec > 0)
{
var trimArr = new char[] { '<', 'E', 'O', 'F', '>' };
var msg = Encoding.ASCII.GetString(bytes, 0, bytesRec).TrimEnd(trimArr);
Console.WriteLine(msg);
}
}
catch (SocketException e)
{
Console.WriteLine("Connection lost");
Console.ReadLine();
}

}
}

private static void InitClient()
{
Console.WriteLine("Hello. Enter your name");
name = Console.ReadLine();
}

public static int Main(String[] args)
{
InitClient();
var connected = StartClient();
if (!connected) return 0;

StartReceiving();

while (true)
{
var msg = Console.ReadLine();
SendMessage(msg);
}
return 0;
}
}
53 changes: 53 additions & 0 deletions Lab1_a_Client/Lab1_a_Client/Lab1_a_Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9FB83A5A-7B87-448F-A0CD-270675E13B6E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Lab1_a_Client</RootNamespace>
<AssemblyName>Lab1_a_Client</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Client.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions Lab1_a_Client/Lab1_a_Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Общие сведения об этой сборке предоставляются следующим набором
// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
// связанные со сборкой.
[assembly: AssemblyTitle("Lab1_a_Client")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Lab1_a_Client")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
// COM, задайте атрибуту ComVisible значение TRUE для этого типа.
[assembly: ComVisible(false)]

// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
[assembly: Guid("9fb83a5a-7b87-448f-a0cd-270675e13b6e")]

// Сведения о версии сборки состоят из следующих четырех значений:
//
// Основной номер версии
// Дополнительный номер версии
// Номер сборки
// Редакция
//
// Можно задать все значения или принять номер сборки и номер редакции по умолчанию.
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2d609030daf9fdb4c7b5b0543f78958ffb84320a
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
E:\Education\7Sem\Nets\Lab1\Lab1_a_Client\Lab1_a_Client\bin\Debug\Lab1_a_Client.exe.config
E:\Education\7Sem\Nets\Lab1\Lab1_a_Client\Lab1_a_Client\bin\Debug\Lab1_a_Client.exe
E:\Education\7Sem\Nets\Lab1\Lab1_a_Client\Lab1_a_Client\bin\Debug\Lab1_a_Client.pdb
E:\Education\7Sem\Nets\Lab1\Lab1_a_Client\Lab1_a_Client\obj\Debug\Lab1_a_Client.csprojAssemblyReference.cache
E:\Education\7Sem\Nets\Lab1\Lab1_a_Client\Lab1_a_Client\obj\Debug\Lab1_a_Client.csproj.CoreCompileInputs.cache
E:\Education\7Sem\Nets\Lab1\Lab1_a_Client\Lab1_a_Client\obj\Debug\Lab1_a_Client.exe
E:\Education\7Sem\Nets\Lab1\Lab1_a_Client\Lab1_a_Client\obj\Debug\Lab1_a_Client.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Lab1_a_Server/.vs/Lab1_a_Server/v15/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions Lab1_a_Server/Lab1_a_Server.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.572
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab1_a_Server", "Lab1_a_Server\Lab1_a_Server.csproj", "{CF1DD90A-7B98-498D-B0FA-741ED3062E5D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CF1DD90A-7B98-498D-B0FA-741ED3062E5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF1DD90A-7B98-498D-B0FA-741ED3062E5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF1DD90A-7B98-498D-B0FA-741ED3062E5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF1DD90A-7B98-498D-B0FA-741ED3062E5D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B252243D-F54D-4A60-9A78-B7696B022164}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Lab1_a_Server/Lab1_a_Server/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
52 changes: 52 additions & 0 deletions Lab1_a_Server/Lab1_a_Server/Lab1_a_Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CF1DD90A-7B98-498D-B0FA-741ED3062E5D}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Lab1_a_Server</RootNamespace>
<AssemblyName>Lab1_a_Server</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions Lab1_a_Server/Lab1_a_Server/Lab1_a_Server.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>
Loading