MirSocket.cpp
资源名称:盛大传奇外挂原代码.rar [点击查看]
上传用户:marco7834
上传日期:2010-02-24
资源大小:82k
文件大小:1k
源码类别:
游戏引擎
开发平台:
Visual C++
- // MirSocket.cpp: implementation of the CMirSocket class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "MirSocket.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CMirSocket::CMirSocket()
- {
- }
- CMirSocket::~CMirSocket()
- {
- }
- int CMirSocket::SetNoBlock( SOCKET s )
- {
- unsigned long mode = 1;
- if( ioctlsocket( s, FIONBIO, &mode ) == -1 )
- return 0;
- return 1;
- }
- BOOL CMirSocket::NetStartup()
- {
- WSADATA m_wsaData;
- return (WSAStartup(MAKEWORD(2,2), &m_wsaData) != SOCKET_ERROR);
- }
- BOOL CMirSocket::NetCleanup()
- {
- return WSACleanup();
- }
- SOCKET CMirSocket::OpenConnection( char * ip, unsigned short port )
- {
- LPHOSTENT m_pHost;
- SOCKET s;
- struct sockaddr_in ServAddr;
- m_pHost = gethostbyname(ip);
- s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- ServAddr.sin_family = AF_INET;
- ServAddr.sin_addr.s_addr = *(ULONG *)m_pHost->h_addr_list[0];
- ServAddr.sin_port = htons(port);
- int erri = connect(s, (struct sockaddr *)&ServAddr, sizeof(ServAddr));
- if( erri == -1)
- return 0;
- return s;
- }
- void CMirSocket::CloseConnection( SOCKET s )
- {
- closesocket( s );
- }