@@ -10,6 +10,7 @@ import (
10
10
"github.com/keyvchan/NetAssist/pkg/message"
11
11
)
12
12
13
+ // TCPServer is a TCP server, read from stdin and write to the client and read from the client write it to stdout
13
14
func TCPServer () {
14
15
address := flags .GetArg (3 )
15
16
listener , err := net .Listen ("tcp" , address )
@@ -41,6 +42,7 @@ func TCPServer() {
41
42
42
43
}
43
44
45
+ // accept_conn accepts connections from the listener and adds them to the connections map
44
46
func accept_conn (read_chan chan message.Message , listener net.Listener , connections map [net.Conn ]bool ) {
45
47
for {
46
48
conn , err := listener .Accept ()
@@ -59,6 +61,7 @@ func accept_conn(read_chan chan message.Message, listener net.Listener, connecti
59
61
60
62
}
61
63
64
+ // TCPClient is a TCP client, read from stdin and write to the server and read from the server when it to stdout
62
65
func TCPClient () {
63
66
address := flags .GetArg (3 )
64
67
conn , err := net .Dial ("tcp" , address )
@@ -92,6 +95,7 @@ func TCPClient() {
92
95
<- quit
93
96
}
94
97
98
+ // conn_cleanup removes closed connections from the connections map
95
99
func conn_cleanup (closed_conn chan net.Conn , conns map [net.Conn ]bool ) {
96
100
for {
97
101
conn := <- closed_conn
@@ -101,6 +105,7 @@ func conn_cleanup(closed_conn chan net.Conn, conns map[net.Conn]bool) {
101
105
102
106
}
103
107
108
+ // write_to_conns writes messages to all connections in the connections map
104
109
func write_to_conns (message_chan chan message.Message , connections map [net.Conn ]bool ) {
105
110
for {
106
111
message := <- message_chan
0 commit comments