- Quick start
- Run test
- Output
- Requirements and Goals
- High Level System Design
- The idea behind the project
go run tcp_client.go
go run tcp_server.go
// inside base dir
go test -test.v
// Client side
>> go run tcp_client.go
>> Windson
>> Hello Windson!
>> ^[[A
>> <name> is not printable.
>>
>> <name> should not be empty.
>> Exit
TCP client exiting...
// Server side
>> go run tcp_server.go
This is a TCP server...
Launching Server at 8080
2019/09/29 18:14:29 from [::1]:51602]:51602
2019/09/29 18:14:38 from [::1]:51602
2019/09/29 18:14:48 Client from [::1]:51602 left..
- The client can send
<name>to the server, the server will log the information from the client and return "Hello, !" to the client. - If the
<name>is not printable or empty, the server will return error messages. - The client can leave by sending "Exit" to the server.
Since it's a challenge, I choose to use Golang instead of Python. (I also completed a challenge a week ago using Golang. Please check out fibonacci-sequence and idea behind it). In this project, I will focus on testing and error handling.
I learned how to write better tests in this project, I use table tests and subtests to achieve a better result.
There are lots of ways to handle error in Golang, I learned a lot from this great post Don’t just check errors, handle them gracefully
- If we need to support millions of TCP connections, we can use epoll instead of goroutines for saving memory usage. (From A Million WebSockets and Go)
- Add testing for
tcp_server.goandtcp_client.go
