Skip to content

Instantly share code, notes, and snippets.

@chaliy
Created February 17, 2010 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaliy/306982 to your computer and use it in GitHub Desktop.
Save chaliy/306982 to your computer and use it in GitHub Desktop.
open System
open System.Net
open System.Net.Sockets
open System.Text
open System.IO
let listen port =
let listener = new TcpListener(IPAddress.Any, port)
listener.Start()
let client = listener.AcceptTcpClient()
use stream = client.GetStream()
let mutable continueRead = true
while continueRead do
let buffer = Array.zeroCreate 1024
let read = stream.Read(buffer, 0, 1024)
let text = Encoding.ASCII.GetString(buffer, 0, read)
printf "%s" text
continueRead <- stream.DataAvailable
let responseString = "Hello world!"
let buffer = Encoding.ASCII.GetBytes(responseString)
stream.Write(buffer, 0, buffer.Length)
listener.Stop()
do listen 1201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment