{"id":14911805,"url":"https://github.com/smallnest/smallchat","last_synced_at":"2025-04-06T11:08:28.888Z","repository":{"id":204251312,"uuid":"711421371","full_name":"smallnest/smallchat","owner":"smallnest","description":"A minimal programming example for a chat server in Go","archived":false,"fork":false,"pushed_at":"2024-11-25T10:18:05.000Z","size":346,"stargazers_count":91,"open_issues_count":0,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T09:09:46.119Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smallnest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-29T08:03:59.000Z","updated_at":"2025-01-29T07:08:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"1c43859b-fef1-4091-b967-9aa9794acc66","html_url":"https://github.com/smallnest/smallchat","commit_stats":null,"previous_names":["smallnest/smallchat"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fsmallchat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fsmallchat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fsmallchat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fsmallchat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smallnest","download_url":"https://codeload.github.com/smallnest/smallchat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471519,"owners_count":20944158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-22T20:01:14.152Z","updated_at":"2025-04-06T11:08:28.847Z","avatar_url":"https://github.com/smallnest.png","language":"Go","readme":"# smallchat\nA minimal programming example for a chat server in Go.\n\nRedis作者 Salvatore Sanfilippo 最近创建一个新的演示项目：[smallchat](https://github.com/antirez/smallchat)，用了200行代码实现了一个聊天室。这个项目的目的是展示如何用Go语言实现一个简单的聊天服务器。\n\n他写这个项目的动机如下：\n\n\u003e 昨天我正在与几个前端开发者朋友闲聊,他们距离系统编程有些远。我们回忆起了过去的IRC时光。不可避免地,我说:编写一个非常简单的IRC服务器每个人都应该做一次。这样程序中有非常有趣的部分。一个进程进行多路复用,维护客户端状态,可以用不同的方式实现等等。\n\u003e \n\u003e 然后讨论继续,我想,我会给你们展示一个极简的C语言例子。但是你能编写出啥样的最小聊天服务器呢?要真正做到极简,我们不应该需要任何特殊的客户端，即使不是很完美,它应该可以用`telnet`或`nc`(netcat)作为客户端连接。服务器的主要功能只是接收一些聊天信息并发送给所有其他客户端,这有时称为**扇出**操作。这还需要一个合适的`readline()`函数,然后是缓冲等等。我们想要更简单的:利用内核缓冲区,假装我们每次都从客户端收到一个完整的行(这个假设在实际中通常是正确的,所以这个假设没啥问题)。\n\u003e \n\u003e 好吧,有了这些技巧,我们可以用只有200行代码实现一个聊天室,用户甚至可以设置昵称(当然,不计空格和注释)。由于我将这个小程序作为示例编写给我的朋友,我决定也把它推到Github上。\n\n\n嗯，很有意思，这让我想起我最早在学校了玩BBS的时光，看到大家写的BBS服务端和客户端就觉得很神奇。最近几年我也一直在做网络编程方面的工作，所以我想使用Go语言实现antirez的这个小项目，看看Go语言在网络编程方面的表现如何。\n\n最后以不到100行的代码实现了一个聊天室。\n\n![](chat.png)\n\n\n除去注释，不到一百行：\n![](scc.png)","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallnest%2Fsmallchat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmallnest%2Fsmallchat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallnest%2Fsmallchat/lists"}