aceace001 / SE-Spring2022

1 stars 1 forks source link

Sprint2: backend chatroom #9

Closed rookiefromgis closed 2 years ago

rookiefromgis commented 2 years ago

Basic server construction consists of main.go and server.go. The server contains server-type structure data and three methods: creating a server object, starting the server service, and processing the connection business.

rookiefromgis commented 2 years ago

version2: Realize the broadcast function of users going online and sending messages to each other

1. create a new file user.go to represents the client:

2.Changes in the server.go:

rookiefromgis commented 2 years ago

Version3: Add two new functions: Online users' query and Modify users' name

rookiefromgis commented 2 years ago

Version4: Add function to force offline when timeout and private chat function

rookiefromgis commented 2 years ago

Bug: when running the “go run main.go server.go” command, the terminal shows:

command-line-arguments

.\server.go:16:24: undefined: User .\server.go:28:31: undefined: User .\server.go:50:37: undefined: User .\server.go:60:10: undefined: NewUser

The reason for the error belongs to the multi-file loading problem in Golang. When executing the go run command, we need to include all the .go files to be loaded into the parameters.

Two Solutions:

  1. Enter the command “go run *.go”
  2. Configure Run_kind in the IDE, no error will be reported in package mode but reported in file mode because the function involved is undefined (user. go is not started in the project).
rookiefromgis commented 2 years ago

Bug: ”-net.Dial error: dial tcp 127.0.0.1:8888: connectex: No connection could be made because the target machine actively refused it.“

possible reasons:

  1. The server is not started
  2. The port is occupied(find the port and kill)
  3. Firewall blocking(Authorize as administrator)