2011年12月22日

TCP单线程服务端

摘要: 1 #include <WINSOCK2.H> 2 #include <iostream> 3 #pragma comment(lib, "WS2_32") 4 5 6 UINT SrvThread(LPVOID pParam) 7 { 8 // SOCKET实际上是一个unsigned int类型 9 SOCKET server;10 // WSADATA结构将有WSAStartup函数来填充11 WSADATA wsaData;12 // 对TCP/IP 套接字来说,sockaddr_in结构指定了套接字的地址13 // 其他协议使... 阅读全文

posted @ 2011-12-22 22:05 Sunny_NUAA 阅读(469) 评论(0) 推荐(0) 编辑

CSocket进行UDP通信

摘要: 客户端:MySocket类 1 class MySocket : public CSocket 2 { 3 public: 4 MySocket(); 5 virtual ~MySocket(); 6 SOCKADDR_IN ClientAddr; 7 public: 8 // ClassWizard generated virtual function overrides 9 //{{AFX_VIRTUAL(MySocket)10 public:11 virtual void OnReceive(int nErrorCode);12 v... 阅读全文

posted @ 2011-12-22 21:31 Sunny_NUAA 阅读(9846) 评论(0) 推荐(0) 编辑

CAsyncSocket进行TCP通行

摘要: 服务端代码:CNewSocket类 1 class CNewSocket : public CAsyncSocket 2 { 3 public: 4 UINT m_nLength; 5 char m_szBuffer[4096]; 6 7 public: 8 CNewSocket(); 9 virtual ~CNewSocket();10 public:11 // ClassWizard generated virtual function overrides12 //{{AFX_VIRTUAL(CNewSocket)13 public:14 ... 阅读全文

posted @ 2011-12-22 19:19 Sunny_NUAA 阅读(1066) 评论(0) 推荐(0) 编辑

CAsyncSocket进行UDP通信

摘要: 客户端代码:CString m_ServerIP;CString m_ClientIP;int m_ClientPort;CString m_ReceiveData;UINT m_ServerPort;CAsyncSocket m_sockReceive;m_ServerIP="127.0.0.1";m_ClientIP="127.0.0.1";m_ClientPort=6665;m_ServerPort=6666;void CSocketUDPClientDlg::OnReceive() { // TODO: Add your control noti 阅读全文

posted @ 2011-12-22 16:47 Sunny_NUAA 阅读(1986) 评论(0) 推荐(0) 编辑

导航