如何设计、实现windows下的聊天程序

来源:百度知道 编辑:UC知道 时间:2024/05/12 00:36:28
我正在c语言实训,老师让我们在windows下作一个类似QQ一样的简单聊天程序,需实现一个聊天服务器端和一个聊天客户端,对界面无特殊要求。服务器端和客户端之间通过socket通信,客户端之间也通过socket通信。
实训要求: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.