go 中使用socket范例
生活随笔
收集整理的這篇文章主要介紹了
go 中使用socket范例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
package mainimport ( "fmt" "net" )
func main() { exit := make(chan bool) ip := net.ParseIP("127.0.0.1") addr := net.TCPAddr{ip, 81} go func() { l, e := net.ListenTCP("tcp", &addr) if e != nil { fmt.Println(e) exit <- true return } fmt.Println("accept") for{ c, e := l.AcceptTCP() if e != nil { fmt.Println(e) }else{ c.Write([]byte("hello socket")) c.Close() } } }() <-exit fmt.Println("exit") }
// 附 下面是go1 環境搭建的一片博客
http://toeo.iteye.com/blog/1470598
轉載于:https://my.oschina.net/jingshishengxu/blog/52733
總結
以上是生活随笔為你收集整理的go 中使用socket范例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 黑马程序员——java语言基础——组合,
- 下一篇: 如何设置微信铃声