Commit 92b61e81 authored by Sushant Mahajan's avatar Sushant Mahajan

client.go

parent 4f54a90d
package main package main
import ( import (
"bufio" //"bufio"
"fmt" "fmt"
"net" "net"
"os" //"os"
"strconv"
//"time"
) )
var die bool var die bool
...@@ -26,28 +28,40 @@ func doRead(conn net.Conn) { ...@@ -26,28 +28,40 @@ func doRead(conn net.Conn) {
func tempmain() { func tempmain() {
conn, err := net.Dial("tcp", "localhost:5000") conn, err := net.Dial("tcp", "localhost:5000")
die = false die = false
go doRead(conn) //go doRead(conn)
//time.Sleep(time.Second*10)
if err != nil { if err != nil {
fmt.Println("Err:", err) fmt.Println("Err:", err)
} }
reader := bufio.NewReader(os.Stdin) for i := 0; i < 100; i++ {
data := make([]byte, 1024)
for { conn.Write([]byte("set abc" + strconv.Itoa(i) + " 200 10\r\nabcd\nkefgh\r\n"))
if die { //time.Sleep(time.Millisecond)
break n, err := conn.Read(data)
//fmt.Println(data[:n], err)
if err == nil {
fmt.Println(string(data[:n]))
} }
msg, err := reader.ReadString('\n')
if err != nil {
fmt.Println("Err: ", err)
}
fmt.Println(msg)
buf := []byte(msg)[0 : len(msg)-1]
buf = append(buf, []byte("\r\n")...)
fmt.Println(len(buf))
conn.Write(buf)
} }
//reader := bufio.NewReader(os.Stdin)
//for {
// if die {
// break
// }
// msg, err := reader.ReadString('\n')
// if err != nil {
// fmt.Println("Err: ", err)
// }
// fmt.Println(msg)
// buf := []byte(msg)[0 : len(msg)-1]
// buf = append(buf, []byte("\r\n")...)
// fmt.Println(len(buf))
// conn.Write(buf)
//}
conn.Close() conn.Close()
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment