# socketChatRoom **Repository Path**: xjtu-net5-1/socket-chat-room ## Basic Information - **Project Name**: socketChatRoom - **Description**: 2022年网络socket编程实验 用c++基于UDP/TCP实现聊天室,文件传输功能 - **Primary Language**: C++ - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2022-04-17 - **Last Updated**: 2024-12-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 简介 linux服务器与windows用户通过socket进行通信的程序 + 项目目录 + 头文件 + env.h:环境变量 + messageStruct.h:网络层数据包结构 + messageClass.hpp:对网络层数据包操作的封装 + userClass.hpp: 对验证用户的封装 + linuxUDPsocket.hpp: 对 linux udp 操作的封装,简化代码 + winUDPsocket.hpp: 对 windows udp 操作的封装,简化代码 + winTCPsocket.hpp: 对 windows tcp 操作的封装,简化代码 + 源代码 + client.cpp:windows 客户端 socket 逻辑 + server.cpp:linux 服务端 socket 逻辑 + 其他文件 + userinfo.dat: 存储用户信息的文件,17字节为一个用户,前8为用户名,中间一位为间隔符,后8为密码 + reg: 用于服务端注册用户的程序,会记录用户输入到userinfo.dat + print: 用于调试时输出当前所有用户的信息 ### 如何使用 #### server ``` g++ server.cpp -o server.exe -lpthread ./server.exe 25525 # env 文件中 SERVER_PORT 为 25525 ``` #### windows ``` g++ client.cpp -o client.exe client.exe ``` windows `client.cpp` 编译时如出现 ``` C:\Windows\TEMP\ccp6VCFU.o:client.cpp:(.text+0x7c): undefined reference to `__imp_WSAStartup' C:\Windows\TEMP\ccp6VCFU.o:client.cpp:(.text+0x95): undefined reference to `__imp_socket' C:\Windows\TEMP\ccp6VCFU.o:client.cpp:(.text+0xcd): undefined reference to `__imp_htonl' C:\Windows\TEMP\ccp6VCFU.o:client.cpp:(.text+0xe1): undefined reference to `__imp_htons' C:\Windows\TEMP\ccp6VCFU.o:client.cpp:(.text+0x108): undefined reference to `__imp_connect' C:\Windows\TEMP\ccp6VCFU.o:client.cpp:(.text+0x155): undefined reference to `__imp_recv' C:\Windows\TEMP\ccp6VCFU.o:client.cpp:(.text+0x17b): undefined reference to `__imp_closesocket' C:\Windows\TEMP\ccp6VCFU.o:client.cpp:(.text+0x184): undefined reference to `__imp_WSACleanup' ``` 请使用`g++ client.cpp -lwsock32`进行编译