فهرست منبع

Created the beginning of the server. It can accepts clients and listen to their request in different thread(s)

jancoow 10 سال پیش
والد
کامیت
fc631c9aaf

+ 0 - 15
Proftaak Remote Healthcare/ConsoleApplication1/Program.cs

@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ConsoleApplication1
-{
-    class Program
-    {
-        static void Main(string[] args)
-        {
-        }
-    }
-}

+ 0 - 0
Proftaak Remote Healthcare/ConsoleApplication1/App.config → Proftaak Remote Healthcare/Server/App.config


+ 59 - 0
Proftaak Remote Healthcare/Server/Program.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Threading;
+using System.Net.Sockets;
+using System.Text;
+using System.IO;
+using System.Net;
+
+namespace Server
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            Console.WriteLine("Server gestart");
+
+            TcpListener serverSocket = new TcpListener(80);
+            serverSocket.Start();
+
+            while (true)
+            {
+                Console.WriteLine("Waiting for clients..");
+               new Client(serverSocket.AcceptTcpClient());
+            }
+
+            serverSocket.Stop();
+            Console.WriteLine("Server afsluiten");
+        }
+    }
+    public class Client
+    {
+        TcpClient client;
+        NetworkStream networkStream;
+        public Client(TcpClient socket)
+        {
+            client = socket;
+            networkStream = client.GetStream();
+            Console.WriteLine("New client connected");
+            Thread t = new Thread(receive);
+            t.Start();
+        }
+
+        public void receive()
+        {
+            while (true)
+            {
+                byte[] bytesFrom = new byte[(int)client.ReceiveBufferSize];
+                networkStream.Read(bytesFrom, 0, (int)client.ReceiveBufferSize);
+                String response = Encoding.ASCII.GetString(bytesFrom);
+                //Hier moet wat met de response gedaan worden.
+            }
+        }
+        public void sendString(string s)
+        {
+            byte[] b = Encoding.ASCII.GetBytes(s);
+            networkStream.Write(b, 0, b.Length);
+            networkStream.Flush();
+        }
+    }
+}

+ 3 - 3
Proftaak Remote Healthcare/ConsoleApplication1/Properties/AssemblyInfo.cs → Proftaak Remote Healthcare/Server/Properties/AssemblyInfo.cs

@@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
 // General Information about an assembly is controlled through the following 
 // set of attributes. Change these attribute values to modify the information
 // associated with an assembly.
-[assembly: AssemblyTitle("ConsoleApplication1")]
+[assembly: AssemblyTitle("Server")]
 [assembly: AssemblyDescription("")]
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("ConsoleApplication1")]
+[assembly: AssemblyProduct("Server")]
 [assembly: AssemblyCopyright("Copyright ©  2015")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
 [assembly: ComVisible(false)]
 
 // The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("21feae1b-dc2c-4788-9d25-c7f40f1b3126")]
+[assembly: Guid("06c35f7a-ba2d-4f7d-8f8e-39636027707b")]
 
 // Version information for an assembly consists of the following four values:
 //

+ 3 - 3
Proftaak Remote Healthcare/ConsoleApplication1/ConsoleApplication1.csproj → Proftaak Remote Healthcare/Server/Server.csproj

@@ -4,11 +4,11 @@
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{21FEAE1B-DC2C-4788-9D25-C7F40F1B3126}</ProjectGuid>
+    <ProjectGuid>{06C35F7A-BA2D-4F7D-8F8E-39636027707B}</ProjectGuid>
     <OutputType>Exe</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>ConsoleApplication1</RootNamespace>
-    <AssemblyName>ConsoleApplication1</AssemblyName>
+    <RootNamespace>Server</RootNamespace>
+    <AssemblyName>Server</AssemblyName>
     <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>