Created
April 9, 2013 20:32
-
-
Save chribben/5349134 to your computer and use it in GitHub Desktop.
Tcp message passing in F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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