{"id":16204488,"url":"https://github.com/jasonxudeveloper/realtime-socket-chat","last_synced_at":"2025-03-19T07:31:17.191Z","repository":{"id":108807340,"uuid":"263839001","full_name":"JasonXuDeveloper/Realtime-Socket-Chat","owner":"JasonXuDeveloper","description":"A realtime chat code based on C# client with Node.js Server, supports multi-chatroom; private individual chats | 基于C#客户端以及Node.js服务端的聊天室，支持多人聊天室以及私人聊天","archived":false,"fork":false,"pushed_at":"2020-05-14T09:15:25.000Z","size":21334,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T04:43:15.117Z","etag":null,"topics":["chat","chatroom","nodejs","socket","unity-3d"],"latest_commit_sha":null,"homepage":null,"language":"C#","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/JasonXuDeveloper.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":"2020-05-14T06:55:15.000Z","updated_at":"2024-07-15T14:51:12.000Z","dependencies_parsed_at":"2023-07-15T20:16:38.256Z","dependency_job_id":null,"html_url":"https://github.com/JasonXuDeveloper/Realtime-Socket-Chat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonXuDeveloper%2FRealtime-Socket-Chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonXuDeveloper%2FRealtime-Socket-Chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonXuDeveloper%2FRealtime-Socket-Chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonXuDeveloper%2FRealtime-Socket-Chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JasonXuDeveloper","download_url":"https://codeload.github.com/JasonXuDeveloper/Realtime-Socket-Chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244379142,"owners_count":20443406,"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":["chat","chatroom","nodejs","socket","unity-3d"],"created_at":"2024-10-10T09:58:25.718Z","updated_at":"2025-03-19T07:31:17.184Z","avatar_url":"https://github.com/JasonXuDeveloper.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Realtime-Chat\nA realtime chat code based on C# client with Node.js Server, supports multi-chatroom \u0026amp; private individual chats\n\u003cbr\u003e\n[中文请点这里](#实时聊天系统)\n\n## SETUP\n### Server side\nNote: This is a setup example on CentOS Server\n\nInstall Node.js\n```sh\n$ cd / # go to root dictionary\n$ wget https://nodejs.org/dist/latest-v9.x/node-v9.4.0-linux-x64.tar.xz # download node.js v9 from official site\n```\n\nDecompress Node.js\n```sh\n$ tar -xvJf node-v9.4.0-linux-x64.tar.xz\n```\n\nMove it to /usr/local Dictionary\n```sh\n$ mv node-v9.4.0-linux-x64 /usr/local/node-v9\n```\n\nCreate Symbolic Links\n```sh\n$ ln -s /usr/local/node-v9/bin/node /bin/node\n```\n\nSetup NPM\n```sh\n$ ln -s /usr/local/node-v9/bin/npm /bin/npm\n```\n\nSetup environment variable\n```sh\n$ echo 'export PATH=/usr/local/node-v9/bin:$PATH' \u003e\u003e /etc/profile\n$ source /etc/profile\n```\n\nUse NPM\n```sh\n$ npm install forever -g\n```\n\nInstall socket.io\n```sh\n$ npm install socket.io\n```\n\nClone this project\n```sh\n$ git clone https://github.com/JasonXuDeveloper/Realtime-Socket-Chat.git\n```\n\nGo to Server dictionary\n```sh\n$ cd Server\n```\n\nStart the Server (make sure you have access to port 4567)\n```sh\n$ node main.js\nServer start....\n```\n\n**Server side setup is now DONE!!!**\n\n\n### Client side\nNote: Client setup fits all operating systems which can install Unity3d (or you build project to different platforms via Unity)\n\n1. Press [Here](https://github.com/JasonXuDeveloper/Realtime-Socket-Chat/tree/master) to go to our Github page (ignore if you are already here)\n2. Download ZIP\n3. Decompress ZIP\n4. Go to Unity-DEMO/Asstes/Scenes\n5. Double click file: \"DEMO SCENE.unity\"\n6. On hierarchy, select SocketIO, and on inspector, change ws://127.0.0.1:4567/socket.io/?EIO=4\u0026transport=websocket to you ip address (ws://your_ip:4567/socket.io/?EIO=4\u0026transport=websocket)\n7. Run it and enjoy your chatroom!\n\n## C# Cores\n#### Client.cs\nCore class which sends messages and does server-side actions\n```C#\n//This is the base class on c# which is the core code\n[Serializable]\npublic class Client\n{\n    //Use this method to set a new ID (Name) for a client\n    public void SetID(string newID)\n    {\n        //xxx;\n        //xxx;\n    }\n    \n    //Login to server so that the client can send messages\n    public void Login()\n    {\n        //xxx;\n        //xxx;\n    }\n    \n    //Use this method to send message\n    public async void SendMessage(string msg)\n    {\n        //xxx\n        //xxx\n    }\n}\n/*\n * Run server code first\n * Then, try this code (or try the unity example)\n */\npublic class Main\n{\n    void Main()\n    {\n        var Client = new Client();\n        Client.SetID(\"Test\");\n        Client.SendMessage(\"Hi There!\");\n        //See what will happen on the server\n    }\n}\n```\n\n\u003cbr\u003e\n\n#### Chatroom.cs\nThis is the main UI Setup \u0026 Server listener code.\nSee Unity-DEMO/Scripts/Chatroom.cs for details.\n\n```c#\n//What we have is the most imortant piece of code here:\nSocket.On(\"recieveMsg\",(e)=\u003e\n{\n    var id = e.data.list[0].str;\n    var text = e.data.list[1].str;\n    //Codes here for showing what we recieved;\n});\n```\n\n\u003cbr\u003e\n\n## Server cores\nYou can check the history.txt file in Server dictionary, which is the chat history overall\n```js\nvar server=require('socket.io');//socket\nvar fs=require('fs');//file stream\n\n\n//saves chat history\nfs.access('history.txt',(err)=\u003e{\n    if(err){\n        fs.writeFile('history.txt','','utf8',function(error){\n            if(error){\n                console.log(error);\n                return false;\n            }\n            console.log('Successfully created history.txt');\n        });\n    }\n});\n\nvar io = new server(4567);//you can change 4567 here to port you want\n\n\nconsole.log('Server Start....');\n\nvar ids = [];//a list which saves current ids to avoid same names\n\n//a function which makes unique id\nfunction guid() {\n    return xxx;\n}\n\n//when socker connected\nio.on('connection', function(socket){\n    //xxx;\n}\n```\n\n## What will be coming soom?\n* ~~C# based client source code (running on Unity 3d)~~\n* ~~Node.js based server source code (running on Server, could be Virtual Machine, Node.js supports Windows, MaxOS and all kind of Linux)~~\n* ~~Unity3d DEMO PROJECT~~\n* Chat between individuals\n\n## About developer\nIf you have any issues,\nplease follow [jason_the_developer](https://www.instagram.com/jason_the_programmer/) at instagram and send me messages!\n\n\u003cbr\u003e\u003cbr\u003e\u003chr\u003e\u003cbr\u003e\n\n\n# 实时聊天系统\n基于C#客户端以及Node.js服务端的聊天室，支持多人聊天室以及私人聊天\n\n## 部署\n### 服务端\n注意：该服务端部署仅适用于CentOS机器\n\n下载Node.js\n```sh\n$ cd / # 切换到根目录\n$ wget https://nodejs.org/dist/latest-v9.x/node-v9.4.0-linux-x64.tar.xz # 从官网下载\n```\n\n解压Node.js\n```sh\n$ tar -xvJf node-v9.4.0-linux-x64.tar.xz\n```\n\n移动解压文件到/usr/local Dictionary\n```sh\n$ mv node-v9.4.0-linux-x64 /usr/local/node-v9\n```\n\n创建软链接\n```sh\n$ ln -s /usr/local/node-v9/bin/node /bin/node\n```\n\n配置NPM\n```sh\n$ ln -s /usr/local/node-v9/bin/npm /bin/npm\n```\n\n配置环境变量\n```sh\n$ echo 'export PATH=/usr/local/node-v9/bin:$PATH' \u003e\u003e /etc/profile\n$ source /etc/profile\n```\n\n使用NPM\n```sh\n$ npm install forever -g\n```\n\n下载socket.io\n```sh\n$ npm install socket.io\n```\n\n克隆该项目\n```sh\n$ git clone https://github.com/JasonXuDeveloper/Realtime-Socket-Chat.git\n```\n\n进入服务端目录\n```sh\n$ cd Server\n```\n\n启动服务器（确保端口4567可用）\n```sh\n$ node main.js\nServer start....\n```\n\n**服务端配置完成！！！**\n\n### 客户端\n注意：客户端可以在任何可以使用Unity3d的操作系统运行（或者通过Unity打包项目到其他平台）\n\n1. 点击[这里](https://github.com/JasonXuDeveloper/Realtime-Socket-Chat/tree/master)进入项目Github地址（如果你已经在这个页面请忽略）\n2. 下载项目ZIP\n3. 解压ZIP\n4. 进入目录Unity-DEMO/Asstes/Scenes\n5. 双击文件： \"DEMO SCENE.unity\"\n6. 在阶层中，选择SocketIO，同时，在检查器中，将ws://127.0.0.1:4567/socket.io/?EIO=4\u0026transport=websocket改为你的ip地址(ws://your_ip:4567/socket.io/?EIO=4\u0026transport=websocket)\n7. 运行并尽情测试你的聊天室是否可用！\n\n## C# 核心\n#### Client.cs\n处理服务器回调以及发送信息的核心代码\n```C#\n//This is the base class on c# which is the core code\n[Serializable]\npublic class Client\n{\n    //Use this method to set a new ID (Name) for a client\n    public void SetID(string newID)\n    {\n        //xxx;\n        //xxx;\n    }\n    \n    //Login to server so that the client can send messages\n    public void Login()\n    {\n        //xxx;\n        //xxx;\n    }\n    \n    //Use this method to send message\n    public async void SendMessage(string msg)\n    {\n        //xxx\n        //xxx\n    }\n}\n/*\n * Run server code first\n * Then, try this code (or try the unity example)\n */\npublic class Main\n{\n    void Main()\n    {\n        var Client = new Client();\n        Client.SetID(\"Test\");\n        Client.SendMessage(\"Hi There!\");\n        //See what will happen on the server\n    }\n}\n```\n\n\u003cbr\u003e\n\n#### Chatroom.cs\n展示UI以及接收服务器信息的核心代码\n查看Unity-DEMO/Scripts/Chatroom.cs以获得更多详情\n\n```c#\n//What we have is the most imortant piece of code here:\nSocket.On(\"recieveMsg\",(e)=\u003e\n{\n    var id = e.data.list[0].str;\n    var text = e.data.list[1].str;\n    //Codes here for showing what we recieved;\n});\n```\n\n\u003cbr\u003e\n\n## 服务端核心\n可以在Server目录下History.txt查阅完整全部客户聊天记录\n```js\nvar server=require('socket.io');//socket\nvar fs=require('fs');//file stream\n\n\n//saves chat history\nfs.access('history.txt',(err)=\u003e{\n    if(err){\n        fs.writeFile('history.txt','','utf8',function(error){\n            if(error){\n                console.log(error);\n                return false;\n            }\n            console.log('Successfully created history.txt');\n        });\n    }\n});\n\nvar io = new server(4567);//you can change 4567 here to port you want\n\n\nconsole.log('Server Start....');\n\nvar ids = [];//a list which saves current ids to avoid same names\n\n//a function which makes unique id\nfunction guid() {\n    return xxx;\n}\n\n//when socker connected\nio.on('connection', function(socket){\n    //xxx;\n}\n```\n\n## 接下来会有什么？\n* ~~基于C#的Unity3d客户端~~\n* ~~Node.js服务端源代码~~\n* ~~Unity3d实例项目~~\n* 私聊解决方案\n\n## 关于作者\n有问题请加作者QQ：2313551611，\n并标明是从Github来反馈问题的！\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonxudeveloper%2Frealtime-socket-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasonxudeveloper%2Frealtime-socket-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonxudeveloper%2Frealtime-socket-chat/lists"}