如何设计、实现windows下的聊天程序
来源:百度知道 编辑:UC知道 时间:2024/05/12 00:36:28
实训要求:1.服务器端需要能够处理客户端的请求,包括用户注册、登陆、下线、生成在线用户列表、查询某个在线用户的信息等。 2.客户端保持与服务器端的连接。 3.客户端之间互相通信,可以传递文字信息,并可以传送文件。
急着用,希望尽快各位电脑高手帮助我,谢谢
可以给你一个简单的服务端和客户端的代码,其余功能自己添加!
服务端:
#include <stdio.h>
#include <Winsock2.h>
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL.