android p2p两篇文章:
http://blog.csdn.net/gophers/article/details/38060307
http://blog.csdn.net/max2005/article/details/12237905
官方文档:http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html
golang,
http://blog.csdn.net/gophers/article/details/37815009
- func (srv *Server) Serve(l net.Listener) error {
- defer l.Close()
- var tempDelay time.Duration
- // 这个循环就是服务器的主循环了,通过传进来的listener接收来自客户端的请求并建立连接,
- // 然后为每一个连接创建routine执行c.serve(),这个c.serve就是具体的服务处理了
- for {
- rw, e := l.Accept()
- if e != nil {
- if ne, ok := e.(net.Error); ok && ne.Temporary() {
- if tempDelay == 0 {
- tempDelay = 5 * time.Millisecond
- } else {
- tempDelay *= 2
- }
- if max := 1 * time.Second; tempDelay > max {
- tempDelay = max
- }
- srv.logf("http: Accept error: %v; retrying in %v", e, tempDelay)
- time.Sleep(tempDelay)
- continue
- }
- return e
- }
- tempDelay = 0
- c, err := srv.newConn(rw)
- if err != nil {
- continue
- }
- c.setState(c.rwc, StateNew) // before Serve can return
- go c.serve() // <-这里为每一个建立的连接创建routine之后进行服务
- }
- }
有疑问加站长微信联系(非本文作者)