This is a creation in Article, where the information may have evolved or changed.
I wrote a socket to write it with Golang. Very concise, the following directly read the code on the line. The notes are written in great detail. Do not understand the comments below
Server-side
Package Mainimport ("Bufio" "FMT" "IO" "NET") Func main () {///Use the TCP protocol to listen on native 8080 Port list, err: = Net. Listen ("TCP", "127.0.0.1:8080") if err! = Nil {fmt. PRINTLN ("Network Monitor failed!") Fmt. PRINTLN (ERR)}//Remember to close the defer list. Close () for {//wait for the link to be assigned to C, ERRC, err: = List If there is a link. Accept () if err! = Nil {fmt. PRINTLN ("Bad link")}//there may be multiple requests sent over so here in parallel way go Handle (c)}}func Handle (conn net. Conn) {defer Conn. Close ()//Create a buffered *reader and read the corresponding data, err: = Bufio. Newreader (conn). ReadString (' \ n ')///If the data reads err will become EOF this is not an error. If err! = Nil && Err! = Io. EOF {fmt. Println (Err. Error ())}fmt. PRINTLN (data)}
Client
The package Mainimport ("FMT" "NET" "OS") Func main () {///via TCP protocol is linked to native 8080 Port con, err: = Net. Dial ("TCP", "127.0.0.1:8080")//if there is an error stating that the link failed if err! = Nil {fmt. PRINTLN ("Connection server-side failure") FMT. Println (Err. Error ()) OS. Exit (0)}//Remember to close defer con. Close ()//start sending Hellonum to server side, write_err: = con. Write ([]byte ("Hello"))//If the write has a problem output corresponding error message if Write_err! = nil {fmt. Println (Write_err. Error ())}//If there is no problem. Displays the corresponding write length of FMT. PRINTLN (NUM)}