Skip to content

Commit f6d3b64

Browse files
committed
client init
1 parent 3a3b0ad commit f6d3b64

File tree

7 files changed

+131
-0
lines changed

7 files changed

+131
-0
lines changed

pkg/linux_amd64/Misc.a

314 Bytes
Binary file not shown.

src/BotClient/bot.log

Whitespace-only changes.

src/BotClient/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"API": "theApi",
3+
"CHAT_ID": "-1001329388485",
4+
"CHAT_TYPE": "channel"
5+
}

src/BotClient/initConn.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package main
2+
3+
import (
4+
misc "Misc"
5+
"bufio"
6+
"fmt"
7+
"net"
8+
"os"
9+
)
10+
11+
//Conn ...
12+
var Conn net.Conn
13+
14+
// initCLientConn initializes client connection
15+
func initClientConn(netType string, addr string, port string) {
16+
Conn, err := net.Dial("tcp", addr+":"+port)
17+
if err != nil {
18+
misc.Err("cannot connect to server")
19+
}
20+
misc.Info("Client Connected")
21+
go handleClientInput(Conn)
22+
handleClientConn(Conn)
23+
// reader := bufio.NewReader(os.Stdin)
24+
// for {
25+
// text, err := reader.ReadString('\n')
26+
// if err != nil {
27+
// misc.Err("connot read from input", err)
28+
// }
29+
// handleClientInput(text)
30+
// }
31+
}
32+
33+
func handleClientConn(c net.Conn) {
34+
_, err := c.Write([]byte(">setbotname jhon"))
35+
if err != nil {
36+
return
37+
}
38+
for {
39+
buf := make([]byte, 500)
40+
nr, err := c.Read(buf)
41+
if err != nil {
42+
43+
}
44+
data := string(buf[0:nr])
45+
if data == "Name Taken" {
46+
_, err = c.Write([]byte(">setbotname meron"))
47+
}
48+
fmt.Println(">server", data)
49+
}
50+
}
51+
52+
func handleClientInput(c net.Conn) {
53+
reader := bufio.NewReader(os.Stdin)
54+
for {
55+
msg, err := reader.ReadString('\n')
56+
if err != nil {
57+
misc.Warning("cannot send a message", err)
58+
continue
59+
}
60+
c.Write([]byte(msg + "\n"))
61+
}
62+
}

src/BotClient/logger.log

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
DANGER 2019/03/07 13:07:24 util.go:31: cannot connect to client
2+
DANGER 2019/03/07 13:07:54 util.go:31: cannot connect to client
3+
INFO 2019/03/07 13:07:54 util.go:55: Client started
4+
INFO 2019/03/07 13:07:54 util.go:55: Text to send
5+
DANGER 2019/03/07 13:08:59 util.go:31: cannot connect to client
6+
INFO 2019/03/07 13:08:59 util.go:55: Client started
7+
INFO 2019/03/07 13:08:59 util.go:55: Text to send
8+
ERROR 2019/03/07 13:09:46 util.go:45: cannot connect to server
9+
INFO 2019/03/07 13:10:32 util.go:55: Client started
10+
INFO 2019/03/07 13:10:32 util.go:55: Text to send
11+
INFO 2019/03/07 13:10:55 util.go:55: &{{0xc0000ca080}}
12+
13+
14+
INFO 2019/03/07 13:10:55 util.go:55: message from server:
15+
INFO 2019/03/07 13:10:55 util.go:55: Text to send
16+
INFO 2019/03/07 13:11:47 util.go:55: &{{0xc0000ca080}}
17+
18+
19+
INFO 2019/03/07 13:11:47 util.go:55: message from server:
20+
INFO 2019/03/07 13:11:47 util.go:55: Text to send
21+
INFO 2019/03/07 13:11:50 util.go:55: &{{0xc0000ca080}} hhhh
22+
23+
24+
INFO 2019/03/07 13:11:50 util.go:55: message from server:
25+
INFO 2019/03/07 13:11:50 util.go:55: Text to send
26+
INFO 2019/03/07 13:16:31 util.go:55: Client started
27+
INFO 2019/03/07 14:36:13 util.go:55: Client Connected
28+
INFO 2019/03/07 14:39:49 util.go:55: Client Connected
29+
INFO 2019/03/07 14:44:40 util.go:55: Client Connected
30+
INFO 2019/03/07 14:46:37 util.go:55: Client Connected
31+
INFO 2019/03/07 15:50:54 util.go:55: Client Connected
32+
INFO 2019/03/07 15:51:54 util.go:55: Client Connected
33+
INFO 2019/03/07 15:58:27 util.go:55: Client Connected
34+
INFO 2019/03/07 15:58:52 util.go:55: Client Connected

src/BotClient/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package main
2+
3+
func main() {
4+
initClientConn("tcp4", "localhost", "8080")
5+
}

src/BotServer/logger.log

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,28 @@ INFO 2019/03/06 16:08:16 util.go:55: Bot < jhon > has Joined
100100
INFO 2019/03/06 16:09:14 util.go:55: Bot < jhon > has left the room
101101
INFO 2019/03/06 16:13:32 util.go:55: Bot < meron > has left the room
102102
INFO 2019/03/06 16:13:44 util.go:55: Bot < jjjj > has Joined
103+
INFO 2019/03/07 12:09:01 util.go:55: Input from server has initialized
104+
INFO 2019/03/07 12:09:01 util.go:55: Server Has Started
105+
INFO 2019/03/07 12:10:24 util.go:55: Bot < pascal > has Joined
106+
INFO 2019/03/07 13:06:38 util.go:55: Input from server has initialized
107+
INFO 2019/03/07 13:06:38 util.go:55: Server Has Started
108+
INFO 2019/03/07 13:10:22 util.go:55: Input from server has initialized
109+
INFO 2019/03/07 13:10:22 util.go:55: Server Has Started
110+
INFO 2019/03/07 13:10:48 util.go:55: Input from server has initialized
111+
INFO 2019/03/07 13:10:48 util.go:55: Server Has Started
112+
INFO 2019/03/07 13:16:31 util.go:55: Bot < rashford > has Joined
113+
INFO 2019/03/07 13:16:31 util.go:55: Bot < rashford > has left the room
114+
INFO 2019/03/07 14:38:39 util.go:55: Unknow Bot has left the room
115+
INFO 2019/03/07 14:39:49 util.go:55: Bot < jhon > has Joined
116+
INFO 2019/03/07 14:44:29 util.go:55: Bot < jhon > has left the room
117+
INFO 2019/03/07 14:44:40 util.go:55: Bot < jhon > has Joined
118+
INFO 2019/03/07 14:44:58 util.go:55: Bot < jhon > has left the room
119+
INFO 2019/03/07 14:46:37 util.go:55: Bot < jhon > has Joined
120+
INFO 2019/03/07 15:02:43 util.go:55: Bot < jhon > has left the room
121+
INFO 2019/03/07 15:50:54 util.go:55: Bot < jhon > has Joined
122+
INFO 2019/03/07 15:51:54 util.go:55: Can't Add Bot >> Name Taken Generated
123+
INFO 2019/03/07 15:56:09 util.go:55: Unknow Bot has left the room
124+
INFO 2019/03/07 15:58:07 util.go:55: Bot < jhon > has left the room
125+
INFO 2019/03/07 15:58:27 util.go:55: Bot < jhon > has Joined
126+
INFO 2019/03/07 15:58:52 util.go:55: Can't Add Bot >> Name Taken Generated
127+
INFO 2019/03/07 15:58:52 util.go:55: Bot < meron > has Joined

0 commit comments

Comments
 (0)