-
大小: 24.03MB文件类型: .rar金币: 1下载: 0 次发布日期: 2023-06-21
- 语言: C/C++
- 标签: Socket CAsyncSocket TCP
资源简介
一个简单且简陋的小测试程序,支持服务器对某客户端,服务器对所有客户端,客户端之间的通信。TCP Socket基于CAsyncSocket的非阻塞异步通信。效果图详见:http://blog.chinaunix.net/uid-28394603-id-5163195.html
代码片段和文件信息
// NSocket.cpp : 实现文件
//
#include “stdafx.h“
#include “TCPClient.h“
#include “NSocket.h“
// NSocket
NSocket::NSocket(CTCPClientDlg * dlg)
{
m_parentDlg = dlg;
}
NSocket::~NSocket()
{
}
// NSocket 成员函数
void NSocket::OnConnect(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
if(!nErrorCode)
{
m_parentDlg->printfMsg(_T(“Connecting to server!“));
m_parentDlg->OnConnectSucceed();
}
else
{
switch(nErrorCode)
{
case WSAEADDRINUSE:
m_parentDlg->printfMsg(_T(“Connect Faild:The specified address is already in use.“));
break;
case WSAEADDRNOTAVAIL:
m_parentDlg->printfMsg(_T(“Connect Faild:The specified address is not available from the local machine.\n“));
break;
case WSAEAFNOSUPPORT:
m_parentDlg->printfMsg(_T(“Connect Faild:Addresses in the specified family cannot be used with this socket.\n“));
break;
case WSAECONNREFUSED:
m_parentDlg->printfMsg(_T(“Connect Faild:The attempt to connect was forcefully rejected.“));
break;
case WSAEDESTADDRREQ:
m_parentDlg->printfMsg(_T(“Connect Faild:A destination address is required.“));
break;
case WSAEFAULT:
m_parentDlg->printfMsg(_T(“Connect Faild:The lpSockAddrLen argument is incorrect.“));
break;
case WSAEINVAL:
m_parentDlg->printfMsg(_T(“Connect Faild:The socket is already bound to an address.“));
break;
case WSAEISCONN:
m_parentDlg->printfMsg(_T(“Connect Faild:The socket is already connected.“));
break;
case WSAEMFILE:
m_parentDlg->printfMsg(_T(“Connect Faild:No more file descriptors are available.“));
break;
case WSAENETUNREACH:
m_parentDlg->printfMsg(_T(“Connect Faild:The network cannot be reached from this host at this time.“));
break;
case WSAENOBUFS:
m_parentDlg->printfMsg(_T(“Connect Faild:No buffer space is available. The socket cannot be connected.“));
break;
case WSAENOTCONN:
m_parentDlg->printfMsg(_T(“Connect Faild:The socket is not connected.“));
break;
case WSAENOTSOCK:
m_parentDlg->printfMsg(_T(“Connect Faild:The descriptor is a file not a socket.“));
break;
case WSAETIMEDOUT:
m_parentDlg->printfMsg(_T(“Connect Faild:The attempt to connect timed out without establishing a connection. “));
break;
default:
TCHAR szError[256];
_stprintf_s(szError _T(“Connect Faild: %d“) nErrorCode);
m_parentDlg->printfMsg(szError);
break;
}
}
CAsyncSocket::OnConnect(nErrorCode);
}
void NSocket::OnReceive(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
m_parentDlg->onReceive();
CAsyncSocket::OnReceive(nErrorCode);
}
void NSocket::OnClose(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
m_parentDlg->onClose();
CAsyncSocket::OnClose(nErrorCode);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 205312 2015-08-17 14:24 TCPChatRoom\TCPClient\Debug\TCPClient.exe
文件 1236820 2015-08-17 14:24 TCPChatRoom\TCPClient\Debug\TCPClient.ilk
文件 7031808 2015-08-17 14:24 TCPChatRoom\TCPClient\Debug\TCPClient.pdb
文件 4780 2015-08-17 12:03 TCPChatRoom\TCPClient\TCPClient\Debug\TCPClient.Build.CppClean.log
文件 1567 2015-08-17 14:24 TCPChatRoom\TCPClient\TCPClient\Debug\TCPClient.log
文件 2842 2015-08-17 14:24 TCPChatRoom\TCPClient\TCPClient\NSocket.cpp
文件 403 2015-08-17 10:21 TCPChatRoom\TCPClient\TCPClient\NSocket.h
文件 3991 2015-07-15 16:14 TCPChatRoom\TCPClient\TCPClient\ReadMe.txt
文件 67777 2012-01-11 01:22 TCPChatRoom\TCPClient\TCPClient\res\TCPClient.ico
文件 674 2015-07-15 16:14 TCPChatRoom\TCPClient\TCPClient\res\TCPClient.rc2
文件 2062 2015-07-17 11:47 TCPChatRoom\TCPClient\TCPClient\resource.h
文件 142 2015-07-15 16:14 TCPChatRoom\TCPClient\TCPClient\stdafx.cpp
文件 1629 2015-07-15 16:14 TCPChatRoom\TCPClient\TCPClient\stdafx.h
文件 234 2015-07-15 16:14 TCPChatRoom\TCPClient\TCPClient\targetver.h
文件 91492 2015-08-17 10:12 TCPChatRoom\TCPClient\TCPClient\TCPClient.aps
文件 2501 2015-07-15 16:14 TCPChatRoom\TCPClient\TCPClient\TCPClient.cpp
文件 460 2015-07-15 16:14 TCPChatRoom\TCPClient\TCPClient\TCPClient.h
文件 10998 2015-07-17 14:22 TCPChatRoom\TCPClient\TCPClient\TCPClient.rc
文件 6318 2015-08-17 12:03 TCPChatRoom\TCPClient\TCPClient\TCPClient.vcxproj
文件 2246 2015-07-15 17:15 TCPChatRoom\TCPClient\TCPClient\TCPClient.vcxproj.filters
文件 164 2015-07-15 16:59 TCPChatRoom\TCPClient\TCPClient\TCPClient.vcxproj.user
文件 7966 2015-08-17 10:49 TCPChatRoom\TCPClient\TCPClient\TCPClientDlg.cpp
文件 1138 2015-08-17 10:49 TCPChatRoom\TCPClient\TCPClient\TCPClientDlg.h
文件 894 2015-07-15 16:14 TCPChatRoom\TCPClient\TCPClient.sln
..A..H. 29696 2015-08-17 12:06 TCPChatRoom\TCPClient\TCPClient.v11.suo
文件 1531 2015-08-14 15:07 TCPChatRoom\TCPClient.exe.lnk
文件 213504 2015-08-17 14:11 TCPChatRoom\TCPServer\Debug\TCPServer.exe
文件 1294508 2015-08-17 14:11 TCPChatRoom\TCPServer\Debug\TCPServer.ilk
文件 7179264 2015-08-17 14:11 TCPChatRoom\TCPServer\Debug\TCPServer.pdb
文件 6168 2015-08-17 12:01 TCPChatRoom\TCPServer\TCPServer\Debug\TCPServer.Build.CppClean.log
............此处省略84个文件信息
- 上一篇:USB HID STM32 开发资料全集
- 下一篇:MFC编程TCP通信程序
相关资源
- MFC编程TCP通信程序
- 精通Windows Sockets网络开发:基于Visu
- websocket C++ Server端简单demo
- C++纯socket写的FTP服务器
- C++编写基于socket的网络电话
- 基于UDP的Socket 通信源码VC++ 2010 MFC
- Windows下基于socket多线程并发通信的实
- Visual C++网络通信协议分析与应用实现
- QtTcpCpp.rar
- Windows网络编程六种Socket I-O模型C++源代
- MFC_Socket_Server.rar
- 基于C++ socket编程实现的websocket服务器
- vs2010 + MFC + UDP socket 聊天程序。
- mfc Socket 网络调试助手
- MFC下写的一个基于TCP的聊天室程序
- C++写的telnet客户端,VS2010编译通过
- VS2017实现Tcp socket通信C++
- 基于winpcap网络协议编程
- tcp实现的聊天室c++ MFC
- 用Socket写的HTTP类,商业级C++源码。
- socket 实现多人聊天
- 基于TCP/IP和Sqlite3数据库的网络通讯录
- vc++ 编写的基于TCP协议的客户/服务器
- 数据链路层设计与实现
- win sockket全局代理驱动(c++ spi)
- Linuxsocket文件传输C语言支持断点
- socket tcp通信 多客户端
- C语言基于socket多人聊天
- C语言编写Socket编写进程间传文件
- 基于socket通信的,利用MFC实现TCP通信
评论
共有 条评论