Skip to content

Instantly share code, notes, and snippets.

@chribben
Created April 9, 2013 20:32
Show Gist options
  • Save chribben/5349134 to your computer and use it in GitHub Desktop.
Save chribben/5349134 to your computer and use it in GitHub Desktop.
Tcp message passing in F#
open System.Net.Sockets
open System.IO
open System
let port = 1234
let clientProc i =
printfn "Connecting"
let client = new System.Net.Sockets.TcpClient("192.168.48.43", port)
let inew = i+uint64(1)
let sw = new StreamWriter(client.GetStream())
sw.Write(inew.ToString())
sw.Write("\n")
printfn "Sending %u" inew
sw.Flush()
let serverProc =
let l = TcpListener.Create(port)
l.Start()
clientProc 0UL
while true do
printfn "Waiting for client"
use c = l.AcceptTcpClient()
let ns = c.GetStream()
let sr = new StreamReader(ns)
let i = System.UInt64.Parse(sr.ReadLine())
printfn "%u" i
clientProc i
serverProc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment