go 的简单网络框架 kendynet-go

码农软件 · 软件分类 · 网络工具包 · 2019-02-27 14:42:24

软件介绍

kendynet-go 是用 go 语言编写的简单网络框架。

 package main

    import (
            "net"
            tcpsession "kendynet-go/tcpsession"
            packet "kendynet-go/packet"
            "fmt"
           )


    func send_finish (s interface{},wpk *packet.Wpacket){
        session := s.(*tcpsession.Tcpsession)
        session.Close()
    }

    func process_client(session *tcpsession.Tcpsession,rpk *packet.Rpacket){
        session.Send(packet.NewWpacket(rpk.Buffer(),rpk.IsRaw()),send_finish)
    }

    func session_close(session *tcpsession.Tcpsession){
        fmt.Printf("client disconnect\n")
    }

    func main(){
        service := ":8010"
        tcpAddr,err := net.ResolveTCPAddr("tcp4", service)
        if err != nil{
            fmt.Printf("ResolveTCPAddr")
        }
        listener, err := net.ListenTCP("tcp", tcpAddr)
        if err != nil{
            fmt.Printf("ListenTCP")
        }
        for {
            conn, err := listener.Accept()
            if err != nil {
                continue
            }
            session := tcpsession.NewTcpSession(conn,true)
            fmt.Printf("a client comming\n")
            go tcpsession.ProcessSession(session,process_client,session_close)
        }
    }


本文地址:https://codercto.com/soft/d/251.html

Practical Vim, Second Edition

Practical Vim, Second Edition

Drew Neil / The Pragmatic Bookshelf / 2015-10-31 / USD 29.00

Vim is a fast and efficient text editor that will make you a faster and more efficient developer. It’s available on almost every OS, and if you master the techniques in this book, you’ll never need an......一起来看看 《Practical Vim, Second Edition》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码