Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
using System;
using System.Net.Sockets;
using System.Threading;
using System.IO;
public class TestServer
{
public static void Main(string[] args)
{
new TestServer();
}
public TestServer()
{
Listen();
}
TcpListener listener;
private void Listen()
{
listener = new TcpListener(5001);
listener.Start();
while (true)
{
RequestHandler rh = new RequestHandler(listener.AcceptTcpClient());
Thread requestThread = new Thread(new ThreadStart(rh.Handle));
requestThread.Start();
}
}
}
public class RequestHandler
{
TcpClient tcpClient;
public RequestHandler(TcpClient client)
{
tcpClient = client;
}
public void Handle()
{
StreamReader reader = new StreamReader(tcpClient.GetStream(),System.Text.Encoding.ASCII);
StreamWriter writer = new StreamWriter(tcpClient.GetStream());
Console.WriteLine("New client accepted");
string data = "";
int content_length = 0;
while (reader.Peek() != -1)
{
string line = reader.ReadLine();
if (line.StartsWith("Content-Length: "))
content_length = int.Parse(line.Replace("Content-Length: ", ""));
data += line;
}
writer.Write("Blaaaa");
writer.Close();
reader.Close();
tcpClient.Close();
Console.WriteLine("Client disconnected");
}
}
using System;
using System.Net.Sockets;
using System.Threading;
using System.IO;
public class TestServer
{
public static void Main(string[] args)
{
new TestServer();
}
public TestServer()
{
Listen();
}
TcpListener listener;
private void Listen()
{
listener = new TcpListener(5001);
listener.Start();
while (true)
{
RequestHandler rh = new RequestHandler(listener.AcceptTcpClient());
Thread requestThread = new Thread(new ThreadStart(rh.Handle));
requestThread.Start();
}
}
}
public class RequestHandler
{
TcpClient tcpClient;
public RequestHandler(TcpClient client)
{
tcpClient = client;
}
public void Handle()
{
StreamReader reader = new StreamReader(tcpClient.GetStream(),System.Text.Encoding.ASCII);
StreamWriter writer = new StreamWriter(tcpClient.GetStream());
Console.WriteLine("New client accepted");
string data = "";
int content_length = 0;
while (reader.Peek() != -1)
{
string line = reader.ReadLine();
if (line.StartsWith("Content-Length: "))
content_length = int.Parse(line.Replace("Content-Length: ", ""));
data += line;
}
writer.Write("Blaaaa");
writer.Close();
reader.Close();
tcpClient.Close();
Console.WriteLine("Client disconnected");
}
}
using System.IO;
using System;
using System.Net;
using System.Net.Sockets;
public class Test
{
public static void Main(string[] args)
{
string serverName = "localhost";
int serverPort = 5001;
string data = "name=alex";
HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://" + serverName + ":" + serverPort);
req.Method = "PUT";
req.AllowWriteStreamBuffering = true;
Stream reqStream = req.GetRequestStream();
StreamWriter wrtr = new StreamWriter(reqStream);
wrtr.WriteLine(data);
wrtr.Close();
}
}
public void Handle()
{
StreamReader reader = new StreamReader(tcpClient.GetStream(),System.Text.Encoding.ASCII);
StreamWriter writer = new StreamWriter(tcpClient.GetStream());
Console.WriteLine("New client accepted");
string data = "";
int content_length = 0;
while (reader.Peek() != -1)
{
string line = reader.ReadLine();
if (line.StartsWith("Content-Length: "))
content_length = int.Parse(line.Replace("Content-Length: ", ""));
data += line;
}
string buffer = "";
buffer = buffer + "HTTP/1.1 200\r\n";
buffer = buffer + "Server: testserver\r\n";
buffer = buffer + "Accept-Ranges: byte" + "\r\n";
buffer = buffer + "Content-Type: text/html\r\n";
buffer = buffer + "Content-Length: 6\r\n\r\n";
writer.Write(buffer);
writer.Write("Blaaaa\r\n");
writer.Close();
reader.Close();
tcpClient.Close();
Console.WriteLine("Client disconnected");
}