Git Product home page Git Product logo

gochat's Introduction

GoChat

GoChat 是一个基于命令行的聊天程序,使用 Go 语言编写,包含服务器端程序和客户端程序。

功能介绍

GoChat 支持以下功能:

  • 公聊:用户可以向所有在线用户发送消息。
  • 私聊:用户可以向指定用户发送私信。
  • 更新用户名:用户可以更改自己的用户名。
  • 查看在线用户:用户可以查看当前所有在线用户。
  • 自动踢出:当用户长时间未活动时,系统会自动将其踢出。

安装使用

下载源码

git clone https://github.com/wenjunjie/GoChat.git

启动服务器端

在命令行中进入服务器端目录,并执行以下命令:

go run server.go

服务器端默认监听本机 IP 地址和端口号为 8888,可以通过修改源码中的 ipport 变量来更改。

启动客户端

在命令行中进入客户端目录,并执行以下命令:

go run client.go -ip <服务器IP> -port <服务器端口>

其中 <服务器IP><服务器端口> 分别是服务器的 IP 地址和端口号。

客户端命令

客户端支持以下命令:

  • 1:进入公聊模式。
  • 2:进入私聊模式。
  • 3:更新用户名。
  • 4:查看在线用户。
  • 0:退出客户端。

在公聊模式下,用户可以向所有在线用户发送消息;在私聊模式下,用户可以向指定用户发送私信;更新用户名可以更改用户的用户名;查看在线用户可以查看当前所有在线用户。

技术实现

GoChat 使用 Go 语言编写,使用了 netsynctime 等标准库,通过 TCP 协议进行客户端和服务器端之间的通信。

服务器端维护了一个在线用户列表,通过 map 进行存储和管理。客户端和服务器端之间通信采用了 Goroutine 和 Channel 实现并发处理,客户端通过 select 语句实现超时自动踢出功能。

项目贡献者

许可证

GoChat 采用 MIT 许可证。

gochat's People

Contributors

wenjunjiecn avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.