```go
package main
import (
"csxieyi/protocol"
"fmt"
"net"
"os"
"strconv"
"time"
)
func send(conn net.Conn) {
for i := 0; i < 100; i++ {
session := GetSession()
这里错误 : messages := "{\"session":session"}\"
conn.Write(protocol.Enpack([]byte(messages)))
}
fmt.Println("send over")
defer conn.Close()
}
func GetSession() string {
gs1 := time.Now().Unix()
gs2 := strconv.FormatInt(gs1, 10)
return gs2
}
func main() {
server := ":7758"
tcpAddr, err := net.ResolveTCPAddr("tcp4", server)
if err != nil {
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
os.Exit(1)
}
conn, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil {
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
os.Exit(1)
}
fmt.Println("connect success")
send(conn)
}
```
.\main.go:16: syntax error: unexpected : at end of statement
.\main.go:16: newline in string
更多评论
转义不转完全,这个时候,可以使用
messages := `{"session":"session"}`
另外,发帖子不会预览下吗,那么大的预览,样式还发的这么乱七八糟!
#1