鱼C论坛

 找回密码
 立即注册

单线程发包

已有 670 次阅读2015-9-20 17:54 |个人分类:随笔

//send发包TCP
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;
}


if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL.                                  */
WSACleanup( );
return; 
}

/* The WinSock DLL is acceptable. Proceed. */
/*客户端程序流程如下:
1)创建套接字(socket);
2)向服务器发出连接请求(connect);
3)和服务器端进行通信(send/recv);
4)  关闭套接字;*/


SOCKET sClient = {0};
char szSendBuf[MAXBYTE] = "hellokitty!" ;
SOCKADDR_IN sClientAddr = {0} ;

sClientAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
sClientAddr.sin_family = AF_INET;
sClientAddr.sin_port = 12345;

sClient =  socket(AF_INET,SOCK_STREAM,IPPROTO_IP);

connect(sClient,(sockaddr*)&sClientAddr,sizeof(sClientAddr));

UpdateData() ;

m_EditUserName += m_EditPassword ;
//TCHAR *p = m_EditUserName.GetBuffer(0);
//发送  |  套接字  , 数据指针 CString.GetBuffer() , 
//缓冲区长度 CString.Strlen() * sizeof(wchar_t) + sizeof(wchar_t) 


int sd = send(sClient,
(char*)m_EditUserName.GetBuffer(0),
m_EditUserName.GetLength() * 2,
0);

路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-5 12:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部