测试 udp 和 tcp 端口分配的时候重复的几率。新建一个 socket,然后关闭,重复 10000 次。观察重复的端口数量。
go build main.go
package mgoutil | |
import ( | |
"context" | |
"github.com/mongodb/mongo-go-driver/bson" | |
"github.com/mongodb/mongo-go-driver/mongo" | |
"github.com/pkg/errors" | |
) |
package main | |
import ( | |
"encoding/json" | |
"os" | |
"reflect" | |
"text/template" | |
) |
The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.
However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on
// Package main demonstrates a problem with sockets. | |
// run it with: | |
// | |
// go build | |
// ./test 127.0.0.1:1234 | |
// | |
// Nevermind, found the problem (using select wrong) | |
// | |
package main |
// A small SSH daemon providing bash sessions | |
// | |
// Server: | |
// cd my/new/dir/ | |
// #generate server keypair | |
// ssh-keygen -t rsa | |
// go get -v . | |
// go run sshd.go | |
// | |
// Client: |
package main | |
import ( | |
"crypto/tls" | |
"crypto/x509" | |
"flag" | |
"io/ioutil" | |
"log" | |
"net/http" | |
) |
// Implementation of a UDP proxy | |
package main | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"net" | |
"os" |