Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Schreiben Sie einen einfachen Datenbankserver, der Anfangen über den REST-Archtekturstil entgegennimmt und
- * dabei folgende proprietäre Datenbanksprache unterstützt.
- *
- */
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Net.Sockets;
- using System.Data.SqlClient;
- using System.Threading;
- using System.Threading.Tasks;
- namespace EinfacherWebserver
- {
- class Program
- {
- private TcpListener listener;
- private Int32 Port = 13000;
- static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- }
- public void Start()
- {
- listener = new TcpListener(IPAddress.Loopback, Port);
- listener.Start();
- var requests = new Requests();
- while (true)
- {
- var client = listener.AcceptTcpClient();
- requests.Add(client);
- if (!listener.Pending())
- {
- Uri uriAddress = new Uri("http:///localhost:7777");
- requests.Process(uriAddress.LocalPath);
- }
- }
- }
- private class Requests
- {
- Queue<TcpClient> q = new Queue<TcpClient>();
- public void Add(TcpClient client)
- {
- q.Enqueue(client);
- }
- public void Process(string path)
- {
- Console.WriteLine("Queue: " + q.Count);
- while (q.Count > 0)
- {
- try
- {
- var req = new Request(q.Dequeue(), path);
- Console.WriteLine(" " + req.LocalUrl);
- }
- catch (Exception e)
- {
- Console.WriteLine("Error: " + e.Message);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment