Archive for the ‘CLI’ Category
boo network code: simple telnet/web server
Shamelessly modified from the boo example sources, but it’s enough to get you started:
import System.IO
import System.Net
import System.Net.Socketsserver = Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
server.Bind(IPEndPoint(IPAddress.Any, 8200))
server.Listen(1)while true:
socket = server.Accept()
using stream=NetworkStream(socket, true):
print(StreamReader(stream).ReadLine())writer=StreamWriter(stream)
writer.WriteLine(“Ahoy, this server is running: ${shell(‘booc’, ”)}”)
writer.WriteLine(“${shell(‘cat’, ‘/proc/cpuinfo’)}”)
writer.Flush()
MSDN’s System.Net Namespace docs might could also be of use. I’ve tested this on sparc and x86 linux variants with mono.
Hope you find this useful, network programming seems to be a relatively familiar experience if you’ve done it before in another modern language, just took a little bit of scrounging to dig up.