在线等,求C语言高手,实现一个简单的TCPIP程序以实现两台计算机之间的聊天通信,0
功能要求:
1)两个程序,分别是客户端和服务器端
2)可以在客户端或服务器端输入文本信息,回车后将文本信息传输到对端,文本显示在对端屏幕上。
3)服务器可以与一个或多个客户端连接
要求:
1)使用C或C++语言
2)利用TCP socket 实现
3)可以在windows 或 Linux/unix下调试
4)不做界面,直接用显示在console 窗口上
5)必须有足够的注释
老师给了结构// tcpsever.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
void _tmain(int argc, _TCHAR* argv[])
{
WSADATA wsaData;
int Port = 5150;
int Ret;
// Initialize Winsock version 2.2
if ((Ret = WSAStartup(MAKEWORD(2,2), &wsaData)) != 0)
{
// NOTE: Since Winsock failed to load we cannot use WSAGetLastError
// to determine the error code as is normally done when a Winsock
// API fails. We have to report the return status of the function.
printf("WSAStartup failed with error %d\n", Ret);
return;
}
WSACleanup();
}
// tcpsample.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
void _tmain(int argc, _TCHAR* argv[])
{
WSADATA wsaData;
int Ret;
// Initialize Winsock version 2.2
if ((Ret = WSAStartup(MAKEWORD(2,2), &wsaData)) != 0)
{
// NOTE: Since Winsock failed to load we cannot use WSAGetLastError
// to determine the error code as is normally done when a Winsock
// API fails. We have to report the return status of the function.
printf("WSAStartup failed with error %d\n", Ret);
return;
}
感激不尽啊