Advertisement
mkv

C# webserver

mkv
May 8th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.Net.Sockets;
  7.  
  8. namespace wire
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string message = "C# says hello!";
  15.             byte[] data = Encoding.UTF8.GetBytes(message);
  16.             TcpListener server = new TcpListener(80);
  17.             server.Start();
  18.            
  19.             Console.WriteLine("Waiting for the first connection...");
  20.  
  21.             while (true)
  22.             {
  23.                 using (TcpClient connection = server.AcceptTcpClient())
  24.                 {
  25.                     Console.WriteLine("Oh! Hello!");
  26.                     connection.GetStream().Write(data, 0, data.Length);
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement