⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socketdx.cpp

📁 telnet客户端
💻 CPP
字号:
// SocketDx.cpp: implementation of the CSocketDx class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Telnet.h"
#include "Telnet.h"
#include "SocketDx.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSocketDx::CSocketDx(char *strIP,int nPort)
{
unsigned long ip;

  if((*strIP <= '9') && (*strIP >= '0'))
  {
     if((ip = inet_addr(strIP)) == INADDR_NONE)
       printf("invalid host ip given");
  }
  else
  {
    hostent* ent = gethostbyname(strIP);
    if(!ent) printf("\nError\n");
    ip = *(unsigned long*)(ent->h_addr);
  }

	m_sockaddr_in.sin_family = AF_INET;
	m_sockaddr_in.sin_port = htons(nPort);
	m_sockaddr_in.sin_addr = *(in_addr*)&ip;
}
CSocketDx::~CSocketDx()
{

}
int CSocketDx::Create()
{
  m_hSocket = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
  if ( m_hSocket == INVALID_SOCKET) return -1;
  return 0;
}
int CSocketDx::Connect()
{
int nRet;

  nRet = connect(m_hSocket,(sockaddr*)&m_sockaddr_in,sizeof(sockaddr));
  if ( nRet == SOCKET_ERROR ) return -1;
  return 0;
}
SOCKET CSocketDx::TelnetConnect()
{
int nRet;
	
	nRet = Create();
	if ( nRet < 0 ) return NULL;

	nRet = Connect();
	if ( nRet < 0 ) return NULL;

	return m_hSocket;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -