First commit
This commit is contained in:
parent
b378377069
commit
deb52470e5
5 changed files with 134 additions and 0 deletions
44
Client.go
Normal file
44
Client.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const PAYLOAD = "Test data"
|
||||
|
||||
func StartClient() net.Conn {
|
||||
conn := SetupClient(HOST, PORT)
|
||||
|
||||
return conn
|
||||
}
|
||||
|
||||
func SetupClient(host string, port string) net.Conn {
|
||||
// Connect to the server
|
||||
conn, err := net.Dial("tcp", host+":"+port)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
SendData(conn)
|
||||
|
||||
return conn
|
||||
}
|
||||
|
||||
func SendData(conn net.Conn) {
|
||||
counter := 0
|
||||
|
||||
for counter < 10 {
|
||||
// Send some data to the server
|
||||
_, err := conn.Write([]byte(PAYLOAD + " " + strconv.Itoa(counter)))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
counter++
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue