Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 36c0667f

Přidáno uživatelem Eliška Mourycová před téměř 4 roky(ů)

Re #8619. Simple server and client capable of sending and receiving data.

Zobrazit rozdíly:

ClientConnectionTest/ClientTest/ClientTest.sln
1

2
Microsoft Visual Studio Solution File, Format Version 12.00
3
# Visual Studio Version 16
4
VisualStudioVersion = 16.0.31129.286
5
MinimumVisualStudioVersion = 10.0.40219.1
6
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientTest", "ClientTest\ClientTest.csproj", "{E064409E-C390-460F-B41E-4E6E71C04CA0}"
7
EndProject
8
Global
9
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
10
		Debug|Any CPU = Debug|Any CPU
11
		Release|Any CPU = Release|Any CPU
12
	EndGlobalSection
13
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
14
		{E064409E-C390-460F-B41E-4E6E71C04CA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15
		{E064409E-C390-460F-B41E-4E6E71C04CA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16
		{E064409E-C390-460F-B41E-4E6E71C04CA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17
		{E064409E-C390-460F-B41E-4E6E71C04CA0}.Release|Any CPU.Build.0 = Release|Any CPU
18
	EndGlobalSection
19
	GlobalSection(SolutionProperties) = preSolution
20
		HideSolutionNode = FALSE
21
	EndGlobalSection
22
	GlobalSection(ExtensibilityGlobals) = postSolution
23
		SolutionGuid = {7DDA7CFA-9AE1-4546-B764-AEC0161AFD6F}
24
	EndGlobalSection
25
EndGlobal
ClientConnectionTest/ClientTest/ClientTest/ClientTest.csproj
1
<Project Sdk="Microsoft.NET.Sdk">
2

  
3
  <PropertyGroup>
4
    <OutputType>Exe</OutputType>
5
    <TargetFramework>net5.0</TargetFramework>
6
  </PropertyGroup>
7

  
8
</Project>
ClientConnectionTest/ClientTest/ClientTest/Program.cs
1
//// Asynchronous Client Socket Example
2
//// http://msdn.microsoft.com/en-us/library/bew39x2a.aspx
3

  
4
//using System;
5
//using System.Net;
6
//using System.Net.Sockets;
7
//using System.Threading;
8
//using System.Text;
9

  
10
//// State object for receiving data from remote device.
11
//public class StateObject
12
//{
13
//    // Client socket.
14
//    public Socket workSocket = null;
15
//    // Size of receive buffer.
16
//    public const int BufferSize = 256;
17
//    // Receive buffer.
18
//    public byte[] buffer = new byte[BufferSize];
19
//    // Received data string.
20
//    public StringBuilder sb = new StringBuilder();
21
//}
22

  
23
//public class AsynchronousClient
24
//{
25
//    // The port number for the remote device.
26
//    private const int port = 11000;
27

  
28
//    // ManualResetEvent instances signal completion.
29
//    private static ManualResetEvent connectDone =
30
//        new ManualResetEvent(false);
31
//    private static ManualResetEvent sendDone =
32
//        new ManualResetEvent(false);
33
//    private static ManualResetEvent receiveDone =
34
//        new ManualResetEvent(false);
35

  
36
//    // The response from the remote device.
37
//    private static String response = String.Empty;
38

  
39
//    private static void StartClient()
40
//    {
41
//        // Connect to a remote device.
42
//        try
43
//        {
44
//            // Establish the remote endpoint for the socket.
45
//            // The name of the 
46
//            // remote device is "host.contoso.com".
47
//            IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
48
//            IPAddress ipAddress = ipHostInfo.AddressList[0];
49
//            IPEndPoint remoteEP = new IPEndPoint(IPAddress.Loopback, port);
50

  
51
//            // Create a TCP/IP socket.
52
//            Socket client = new Socket(AddressFamily.InterNetwork,
53
//                SocketType.Stream, ProtocolType.Tcp);
54

  
55
//            // Connect to the remote endpoint.
56
//            client.BeginConnect(remoteEP,
57
//                new AsyncCallback(ConnectCallback), client);
58
//            connectDone.WaitOne();
59

  
60
//            // Send test data to the remote device.
61
//            Send(client, "This is a test!");
62
//            sendDone.WaitOne();
63

  
64
//            // Receive the response from the remote device.
65
//            Receive(client);
66
//            receiveDone.WaitOne();
67

  
68
//            // Write the response to the console.
69
//            Console.WriteLine("Response received : {0}", response);
70

  
71
//            // Release the socket.
72
//            client.Shutdown(SocketShutdown.Both);
73
//            client.Close();
74

  
75
//        }
76
//        catch (Exception e)
77
//        {
78
//            Console.WriteLine(e.ToString());
79
//        }
80
//    }
81

  
82
//    private static void ConnectCallback(IAsyncResult ar)
83
//    {
84
//        try
85
//        {
86
//            // Retrieve the socket from the state object.
87
//            Socket client = (Socket)ar.AsyncState;
88

  
89
//            // Complete the connection.
90
//            client.EndConnect(ar);
91

  
92
//            Console.WriteLine("Socket connected to {0}",
93
//                client.RemoteEndPoint.ToString());
94

  
95
//            // Signal that the connection has been made.
96
//            connectDone.Set();
97
//        }
98
//        catch (Exception e)
99
//        {
100
//            Console.WriteLine(e.ToString());
101
//        }
102
//    }
103

  
104
//    private static void Receive(Socket client)
105
//    {
106
//        try
107
//        {
108
//            // Create the state object.
109
//            StateObject state = new StateObject();
110
//            state.workSocket = client;
111

  
112
//            // Begin receiving the data from the remote device.
113
//            client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
114
//                new AsyncCallback(ReceiveCallback), state);
115
//        }
116
//        catch (Exception e)
117
//        {
118
//            Console.WriteLine(e.ToString());
119
//        }
120
//    }
121

  
122
//    private static void ReceiveCallback(IAsyncResult ar)
123
//    {
124
//        try
125
//        {
126
//            // Retrieve the state object and the client socket 
127
//            // from the asynchronous state object.
128
//            StateObject state = (StateObject)ar.AsyncState;
129
//            Socket client = state.workSocket;
130

  
131
//            // Read data from the remote device.
132
//            int bytesRead = client.EndReceive(ar);
133

  
134
//            if (bytesRead > 0)
135
//            {
136
//                // There might be more data, so store the data received so far.
137
//                state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
138

  
139
//                // Get the rest of the data.
140
//                client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
141
//                    new AsyncCallback(ReceiveCallback), state);
142
//            }
143
//            else
144
//            {
145
//                // All the data has arrived; put it in response.
146
//                if (state.sb.Length > 1)
147
//                {
148
//                    response = state.sb.ToString();
149
//                }
150
//                // Signal that all bytes have been received.
151
//                receiveDone.Set();
152
//            }
153
//        }
154
//        catch (Exception e)
155
//        {
156
//            Console.WriteLine(e.ToString());
157
//        }
158
//    }
159

  
160
//    private static void Send(Socket client, String data)
161
//    {
162
//        // Convert the string data to byte data using ASCII encoding.
163
//        byte[] byteData = Encoding.ASCII.GetBytes(data);
164

  
165
//        // Begin sending the data to the remote device.
166
//        client.BeginSend(byteData, 0, byteData.Length, 0,
167
//            new AsyncCallback(SendCallback), client);
168
//    }
169

  
170
//    private static void SendCallback(IAsyncResult ar)
171
//    {
172
//        try
173
//        {
174
//            // Retrieve the socket from the state object.
175
//            Socket client = (Socket)ar.AsyncState;
176

  
177
//            // Complete sending the data to the remote device.
178
//            int bytesSent = client.EndSend(ar);
179
//            Console.WriteLine("Sent {0} bytes to server.", bytesSent);
180

  
181
//            // Signal that all bytes have been sent.
182
//            sendDone.Set();
183
//        }
184
//        catch (Exception e)
185
//        {
186
//            Console.WriteLine(e.ToString());
187
//        }
188
//    }
189

  
190
//    public static void Main(String[] args)
191
//    {
192
//        StartClient();
193
//        Console.ReadLine();
194
//    }
195
//}
196

  
197

  
198

  
199

  
200
using System;
201
using System.Net.Sockets;
202
using System.Text;
203

  
204
class Program
205
{
206
    const int PORT_NO = 11000;
207
    const string SERVER_IP = "127.0.0.1";
208
    static void Main(string[] args)
209
    {
210
        //---data to send to the server---
211
        string textToSend = "ahoj!";
212

  
213
        //---create a TCPClient object at the IP and port no.---
214
        TcpClient client = new TcpClient(SERVER_IP, PORT_NO);
215
        NetworkStream nwStream = client.GetStream();
216

  
217

  
218
		while (true)
219
		{
220
            Console.WriteLine("enter text: ");
221
            textToSend = Console.ReadLine();
222

  
223

  
224
            byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(textToSend);
225

  
226
            //---send the text---
227
            Console.WriteLine("Sending : " + textToSend);
228
            nwStream.Write(bytesToSend, 0, bytesToSend.Length);
229
			if (textToSend.Equals("bye!"))
230
			{
231
                break;
232
			}
233

  
234
            //---read back the text---
235
            byte[] bytesToRead = new byte[client.ReceiveBufferSize];
236
            int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
237
            Console.WriteLine("Received : " + Encoding.ASCII.GetString(bytesToRead, 0, bytesRead));
238
        }
239
        
240
        client.Close();
241
    }
242
}
ClientConnectionTest/ClientTest/ClientTest/bin/Debug/net5.0/ClientTest.deps.json
1
{
2
  "runtimeTarget": {
3
    "name": ".NETCoreApp,Version=v5.0",
4
    "signature": ""
5
  },
6
  "compilationOptions": {},
7
  "targets": {
8
    ".NETCoreApp,Version=v5.0": {
9
      "ClientTest/1.0.0": {
10
        "runtime": {
11
          "ClientTest.dll": {}
12
        }
13
      }
14
    }
15
  },
16
  "libraries": {
17
    "ClientTest/1.0.0": {
18
      "type": "project",
19
      "serviceable": false,
20
      "sha512": ""
21
    }
22
  }
23
}
ClientConnectionTest/ClientTest/ClientTest/bin/Debug/net5.0/ClientTest.runtimeconfig.dev.json
1
{
2
  "runtimeOptions": {
3
    "additionalProbingPaths": [
4
      "C:\\Users\\elisk\\.dotnet\\store\\|arch|\\|tfm|",
5
      "C:\\Users\\elisk\\.nuget\\packages",
6
      "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
7
      "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
8
    ]
9
  }
10
}
ClientConnectionTest/ClientTest/ClientTest/bin/Debug/net5.0/ClientTest.runtimeconfig.json
1
{
2
  "runtimeOptions": {
3
    "tfm": "net5.0",
4
    "framework": {
5
      "name": "Microsoft.NETCore.App",
6
      "version": "5.0.0"
7
    }
8
  }
9
}
ClientConnectionTest/ClientTest/ClientTest/obj/ClientTest.csproj.nuget.dgspec.json
1
{
2
  "format": 1,
3
  "restore": {
4
    "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\ClientConnectionTest\\ClientTest\\ClientTest\\ClientTest.csproj": {}
5
  },
6
  "projects": {
7
    "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\ClientConnectionTest\\ClientTest\\ClientTest\\ClientTest.csproj": {
8
      "version": "1.0.0",
9
      "restore": {
10
        "projectUniqueName": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\ClientConnectionTest\\ClientTest\\ClientTest\\ClientTest.csproj",
11
        "projectName": "ClientTest",
12
        "projectPath": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\ClientConnectionTest\\ClientTest\\ClientTest\\ClientTest.csproj",
13
        "packagesPath": "C:\\Users\\elisk\\.nuget\\packages\\",
14
        "outputPath": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\ClientConnectionTest\\ClientTest\\ClientTest\\obj\\",
15
        "projectStyle": "PackageReference",
16
        "fallbackFolders": [
17
          "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
18
          "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
19
        ],
20
        "configFilePaths": [
21
          "C:\\Users\\elisk\\AppData\\Roaming\\NuGet\\NuGet.Config",
22
          "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
23
          "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
24
        ],
25
        "originalTargetFrameworks": [
26
          "net5.0"
27
        ],
28
        "sources": {
29
          "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
30
          "https://api.nuget.org/v3/index.json": {}
31
        },
32
        "frameworks": {
33
          "net5.0": {
34
            "targetAlias": "net5.0",
35
            "projectReferences": {}
36
          }
37
        },
38
        "warningProperties": {
39
          "warnAsError": [
40
            "NU1605"
41
          ]
42
        }
43
      },
44
      "frameworks": {
45
        "net5.0": {
46
          "targetAlias": "net5.0",
47
          "imports": [
48
            "net461",
49
            "net462",
50
            "net47",
51
            "net471",
52
            "net472",
53
            "net48"
54
          ],
55
          "assetTargetFallback": true,
56
          "warn": true,
57
          "frameworkReferences": {
58
            "Microsoft.NETCore.App": {
59
              "privateAssets": "all"
60
            }
61
          },
62
          "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.201\\RuntimeIdentifierGraph.json"
63
        }
64
      }
65
    }
66
  }
67
}
ClientConnectionTest/ClientTest/ClientTest/obj/ClientTest.csproj.nuget.g.props
1
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
  <PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
4
    <RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
5
    <RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
6
    <ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
7
    <NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
8
    <NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\elisk\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages;C:\Program Files\dotnet\sdk\NuGetFallbackFolder</NuGetPackageFolders>
9
    <NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
10
    <NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.9.1</NuGetToolVersion>
11
  </PropertyGroup>
12
  <ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
13
    <SourceRoot Include="C:\Users\elisk\.nuget\packages\" />
14
    <SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
15
    <SourceRoot Include="C:\Program Files\dotnet\sdk\NuGetFallbackFolder\" />
16
  </ItemGroup>
17
  <PropertyGroup>
18
    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
19
  </PropertyGroup>
20
</Project>
ClientConnectionTest/ClientTest/ClientTest/obj/ClientTest.csproj.nuget.g.targets
1
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
  <PropertyGroup>
4
    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5
  </PropertyGroup>
6
</Project>
ClientConnectionTest/ClientTest/ClientTest/obj/Debug/net5.0/.NETCoreApp,Version=v5.0.AssemblyAttributes.cs
1
// <autogenerated />
2
using System;
3
using System.Reflection;
4
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v5.0", FrameworkDisplayName = "")]
ClientConnectionTest/ClientTest/ClientTest/obj/Debug/net5.0/ClientTest.AssemblyInfo.cs
1
//------------------------------------------------------------------------------
2
// <auto-generated>
3
//     This code was generated by a tool.
4
//     Runtime Version:4.0.30319.42000
5
//
6
//     Changes to this file may cause incorrect behavior and will be lost if
7
//     the code is regenerated.
8
// </auto-generated>
9
//------------------------------------------------------------------------------
10

  
11
using System;
12
using System.Reflection;
13

  
14
[assembly: System.Reflection.AssemblyCompanyAttribute("ClientTest")]
15
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18
[assembly: System.Reflection.AssemblyProductAttribute("ClientTest")]
19
[assembly: System.Reflection.AssemblyTitleAttribute("ClientTest")]
20
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21

  
22
// Generated by the MSBuild WriteCodeFragment class.
23

  
ClientConnectionTest/ClientTest/ClientTest/obj/Debug/net5.0/ClientTest.AssemblyInfoInputs.cache
1
eb314383aa25a94ffe0d94c4615ffa341f193693
ClientConnectionTest/ClientTest/ClientTest/obj/Debug/net5.0/ClientTest.GeneratedMSBuildEditorConfig.editorconfig
1
is_global = true
2
build_property.TargetFramework = net5.0
3
build_property.TargetPlatformMinVersion = 
4
build_property.UsingMicrosoftNETSdkWeb = 
5
build_property.ProjectTypeGuids = 
6
build_property.PublishSingleFile = 
7
build_property.IncludeAllContentForSelfExtract = 
8
build_property._SupportedPlatformList = Android,iOS,Linux,macOS,Windows
ClientConnectionTest/ClientTest/ClientTest/obj/Debug/net5.0/ClientTest.csproj.CoreCompileInputs.cache
1
2286e48d888f91425603880718dc137e6a6fa787
ClientConnectionTest/ClientTest/ClientTest/obj/Debug/net5.0/ClientTest.csproj.FileListAbsolute.txt
1
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\bin\Debug\net5.0\ClientTest.exe
2
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\bin\Debug\net5.0\ClientTest.deps.json
3
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\bin\Debug\net5.0\ClientTest.runtimeconfig.json
4
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\bin\Debug\net5.0\ClientTest.runtimeconfig.dev.json
5
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\bin\Debug\net5.0\ClientTest.dll
6
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\bin\Debug\net5.0\ref\ClientTest.dll
7
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\bin\Debug\net5.0\ClientTest.pdb
8
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\obj\Debug\net5.0\ClientTest.csprojAssemblyReference.cache
9
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\obj\Debug\net5.0\ClientTest.GeneratedMSBuildEditorConfig.editorconfig
10
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\obj\Debug\net5.0\ClientTest.AssemblyInfoInputs.cache
11
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\obj\Debug\net5.0\ClientTest.AssemblyInfo.cs
12
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\obj\Debug\net5.0\ClientTest.csproj.CoreCompileInputs.cache
13
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\obj\Debug\net5.0\ClientTest.dll
14
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\obj\Debug\net5.0\ref\ClientTest.dll
15
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\obj\Debug\net5.0\ClientTest.pdb
16
C:\Users\elisk\Documents\aswi2021tri-musketyri\ClientConnectionTest\ClientTest\ClientTest\obj\Debug\net5.0\ClientTest.genruntimeconfig.cache
ClientConnectionTest/ClientTest/ClientTest/obj/Debug/net5.0/ClientTest.genruntimeconfig.cache
1
5e75078f26ed939765668146ee34e762d1fe23a6
ClientConnectionTest/ClientTest/ClientTest/obj/project.assets.json
1
{
2
  "version": 3,
3
  "targets": {
4
    "net5.0": {}
5
  },
6
  "libraries": {},
7
  "projectFileDependencyGroups": {
8
    "net5.0": []
9
  },
10
  "packageFolders": {
11
    "C:\\Users\\elisk\\.nuget\\packages\\": {},
12
    "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {},
13
    "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder": {}
14
  },
15
  "project": {
16
    "version": "1.0.0",
17
    "restore": {
18
      "projectUniqueName": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\ClientConnectionTest\\ClientTest\\ClientTest\\ClientTest.csproj",
19
      "projectName": "ClientTest",
20
      "projectPath": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\ClientConnectionTest\\ClientTest\\ClientTest\\ClientTest.csproj",
21
      "packagesPath": "C:\\Users\\elisk\\.nuget\\packages\\",
22
      "outputPath": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\ClientConnectionTest\\ClientTest\\ClientTest\\obj\\",
23
      "projectStyle": "PackageReference",
24
      "fallbackFolders": [
25
        "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
26
        "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
27
      ],
28
      "configFilePaths": [
29
        "C:\\Users\\elisk\\AppData\\Roaming\\NuGet\\NuGet.Config",
30
        "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
31
        "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
32
      ],
33
      "originalTargetFrameworks": [
34
        "net5.0"
35
      ],
36
      "sources": {
37
        "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
38
        "https://api.nuget.org/v3/index.json": {}
39
      },
40
      "frameworks": {
41
        "net5.0": {
42
          "targetAlias": "net5.0",
43
          "projectReferences": {}
44
        }
45
      },
46
      "warningProperties": {
47
        "warnAsError": [
48
          "NU1605"
49
        ]
50
      }
51
    },
52
    "frameworks": {
53
      "net5.0": {
54
        "targetAlias": "net5.0",
55
        "imports": [
56
          "net461",
57
          "net462",
58
          "net47",
59
          "net471",
60
          "net472",
61
          "net48"
62
        ],
63
        "assetTargetFallback": true,
64
        "warn": true,
65
        "frameworkReferences": {
66
          "Microsoft.NETCore.App": {
67
            "privateAssets": "all"
68
          }
69
        },
70
        "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.201\\RuntimeIdentifierGraph.json"
71
      }
72
    }
73
  }
74
}
ClientConnectionTest/ClientTest/ClientTest/obj/project.nuget.cache
1
{
2
  "version": 2,
3
  "dgSpecHash": "lM8jVtEbQrnJer4YM6YnoItJzdeA9YlaM/Bnjv08r2LSYcPiYn5ThXxsCE2lrusSCPVT5jW2DvFhk4P3ZqN5VQ==",
4
  "success": true,
5
  "projectFilePath": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\ClientConnectionTest\\ClientTest\\ClientTest\\ClientTest.csproj",
6
  "expectedPackageFiles": [],
7
  "logs": []
8
}
Server/ServerApp/Connection/SocketListener.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Net;
5
using System.Net.Sockets;
6
using System.Text;
7
using System.Threading;
8
using System.Threading.Tasks;
9

  
10
namespace Connection
11
{
12
    // State object for reading client data asynchronously
13
    public class StateObject
14
    {
15
        // Client  socket.
16
        public Socket workSocket = null;
17
        // Size of receive buffer.
18
        public const int BufferSize = 1024;
19
        // Receive buffer.
20
        public byte[] buffer = new byte[BufferSize];
21
        // Received data string.
22
        public StringBuilder sb = new StringBuilder();
23
    }
24

  
25
    public class AsynchronousSocketListener
26
    {
27
        // Thread signal.
28
        public static ManualResetEvent allDone = new ManualResetEvent(false);
29

  
30
        public AsynchronousSocketListener()
31
        {
32
        }
33

  
34
        public static void StartListening()
35
        {
36
            // Data buffer for incoming data.
37
            byte[] bytes = new Byte[1024];
38

  
39
            // Establish the local endpoint for the socket.
40
            // The DNS name of the computer
41
            // running the listener is "host.contoso.com".
42
            IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
43
            IPAddress ipAddress = ipHostInfo.AddressList[1];
44
            Console.WriteLine("ip: " + ipAddress.ToString());
45
            IPEndPoint localEndPoint = new IPEndPoint(/*ipAddress*/IPAddress.Loopback, 11000);
46

  
47
            // Create a TCP/IP socket.
48
            Socket listener = new Socket(AddressFamily.InterNetwork,
49
                SocketType.Stream, ProtocolType.Tcp);
50

  
51
            // Bind the socket to the local endpoint and listen for incoming connections.
52
            try
53
            {
54
                listener.Bind(localEndPoint);
55
                listener.Listen(100);
56

  
57
                while (true)
58
                {
59
                    // Set the event to nonsignaled state.
60
                    allDone.Reset();
61

  
62
                    // Start an asynchronous socket to listen for connections.
63
                    Console.WriteLine("Waiting for a connection...");
64
                    listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
65

  
66
                    // Wait until a connection is made before continuing.
67
                    allDone.WaitOne();
68
                }
69

  
70
            }
71
            catch (Exception e)
72
            {
73
                Console.WriteLine(e.ToString());
74
            }
75

  
76
            Console.WriteLine("\nPress ENTER to continue...");
77
            Console.Read();
78

  
79
        }
80

  
81
        public static void AcceptCallback(IAsyncResult ar)
82
        {
83
            // Signal the main thread to continue.
84
            allDone.Set();
85

  
86
            // Get the socket that handles the client request.
87
            Socket listener = (Socket)ar.AsyncState;
88
            Socket handler = listener.EndAccept(ar);
89

  
90
            // Create the state object.
91
            StateObject state = new StateObject();
92
            state.workSocket = handler;
93
            handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
94
            
95
        }
96

  
97
        public static void ReadCallback(IAsyncResult ar)
98
        {
99
            String content = String.Empty;
100

  
101
            // Retrieve the state object and the handler socket
102
            // from the asynchronous state object.
103
            StateObject state = (StateObject)ar.AsyncState;
104
            Socket handler = state.workSocket;
105

  
106
            // Read data from the client socket. 
107
            int bytesRead = handler.EndReceive(ar);
108

  
109
            if (bytesRead > 0)
110
            {
111
                // There  might be more data, so store the data received so far.
112
                state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
113

  
114
                // Check for end-of-file tag. If it is not there, read 
115
                // more data.
116
                content = state.sb.ToString();
117
                if (content.IndexOf("!") > -1)
118
                {
119
                    // All the data has been read from the 
120
                    // client. Display it on the console.
121
                    Console.WriteLine("Read {0} bytes from socket. \n Data : {1}", content.Length, content);
122
                    // Echo the data back to the client.
123
                    Send(handler, content);
124

  
125
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
126
                }
127
                else
128
                {
129
                    // Not all data received. Get more.
130
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
131
                }
132
            }
133
        }
134

  
135
        private static void Send(Socket handler, String data)
136
        {
137
            // Convert the string data to byte data using ASCII encoding.
138
            byte[] byteData = Encoding.ASCII.GetBytes(data);
139

  
140
            // Begin sending the data to the remote device.
141
            handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler);
142
        }
143

  
144
        private static void SendCallback(IAsyncResult ar)
145
        {
146
            try
147
            {
148
                // Retrieve the socket from the state object.
149
                Socket handler = (Socket)ar.AsyncState;
150

  
151
                // Complete sending the data to the remote device.
152
                int bytesSent = handler.EndSend(ar);
153
                Console.WriteLine("Sent {0} bytes to client.", bytesSent);
154

  
155
                //handler.Shutdown(SocketShutdown.Both);
156
                //handler.Close();
157

  
158
            }
159
            catch (Exception e)
160
            {
161
                Console.WriteLine(e.ToString());
162
            }
163
        }
164
    }
165
}
Server/ServerApp/Program.cs
1
using DataDownload;
1
using Connection;
2
using DataDownload;
2 3
using Parser.Parsers;
3 4
using System;
4 5
using System.Collections.Generic;
......
12 13
    {
13 14
        static void Main(string[] args)
14 15
        {
15
			// ALEX
16
			//CsvParser p = new CsvParser();
16
            // ALEX
17
            //CsvParser p = new CsvParser();
17 18

  
18
			//p.Parse();
19
            //p.Parse();
19 20

  
20 21

  
21 22
            // test scenario - data download:
22
			DataDownloader dd = new DataDownloader();
23
            List<string> savedFiles = new List<string>();
24
            savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, 2017, 2021, 0, 13));
25
            savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, 2017, 2021, 0, 13));
26
            savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, 2017, 2021, 0, 13));
27
           
23
            //DataDownloader dd = new DataDownloader();
24
            //         List<string> savedFiles = new List<string>();
25
            //         savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, 2017, 2021, 0, 13));
26
            //         savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, 2017, 2021, 0, 13));
27
            //         savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, 2017, 2021, 0, 13));
28

  
29

  
30
            //         Console.WriteLine("Saved files: ");
31
            //         foreach(string s in savedFiles)
32
            //{
33
            //             Console.WriteLine(s);
34
            //}
28 35

  
29
            Console.WriteLine("Saved files: ");
30
            foreach(string s in savedFiles)
31
			{
32
                Console.WriteLine(s);
33
			}
36

  
37

  
38
            // test - connection:
39
            AsynchronousSocketListener.StartListening();
40
           
34 41

  
35 42
            Console.ReadLine();
36 43
        }
Server/ServerApp/ServerApp.csproj
45 45
    <Reference Include="System.Xml" />
46 46
  </ItemGroup>
47 47
  <ItemGroup>
48
    <Compile Include="Connection\SocketListener.cs" />
48 49
    <Compile Include="DataDownload\DataDownloader.cs" />
49 50
    <Compile Include="obj\Debug\.NETFramework,Version=v4.7.2.AssemblyAttributes.cs" />
50 51
    <Compile Include="Parser\InputData\CsvDataLoader.cs" />
Server/ServerApp/obj/Debug/ServerApp.csproj.CoreCompileInputs.cache
1
79c6161fcb2ca313d4e4eda6c2e35fd7596821b2
1
a1102017b4b6a9c99797a9b313c5acc5681caeb3

Také k dispozici: Unified diff