Garey's Blog–FreeBSD/PHP/GoLang

文章标签 ‘go’

十一月 7th, 2013

第一个Go程序:UDP日志服务器

No Comments, GoLang, by garey, 10,869 views.

一个简单的UDP日志服务器,用来收集其他程序的字符串日志消息并保存到日志文件中。网络通信基于UDP协议,文件保存方式比较简单,只能作为简单测试使用,不适合线上大规模使用。 package main import ( “fmt” “math/rand” “net” “os” “strconv” “syscall” “time” ) const ( serverPort string = “:8001″ ) type Server struct { conn *net.UDPConn //UDP连接 logs…