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


C++ CreateSocket函数代码示例

本文整理汇总了C++中CreateSocket函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateSocket函数的具体用法?C++ CreateSocket怎么用?C++ CreateSocket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: main

int main(int argc, char **argv)
{
	Preferences::Instance()->SetFile("/boot/home/config/settings/RemoteControl.perfs");
	
	args.porti=4321;
	args.ports=4322;
	args.passwd=0;
	
	parse(argc, argv);
	
	MyApp *app=new MyApp();
	
	int32 socki=CreateSocket(args.porti);
	int32 socks=CreateSocket(args.ports);
	
	if((socki<0) || (socks<0))
		return 1;
	
	new InputListener (socki, args.passwd);
	new ScreenListener(socks, args.passwd);
	
	app->Run();
	
	return 0;
}
开发者ID:puckipedia,项目名称:RemoteControl,代码行数:25,代码来源:Main.cpp

示例2: CreateSocket

void UdpSocket::CreateConnection()
{
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
	if (IsIpv6())
	{
		if (GetSocket() == INVALID_SOCKET)
		{
			SOCKET s = CreateSocket(AF_INET6, SOCK_DGRAM, "udp");
			if (s == INVALID_SOCKET)
			{
				return;
			}
			SetNonblocking(true, s);
			Attach(s);
		}
		return;
	}
#endif
#endif
	if (GetSocket() == INVALID_SOCKET)
	{
		SOCKET s = CreateSocket(AF_INET, SOCK_DGRAM, "udp");
		if (s == INVALID_SOCKET)
		{
			return;
		}
		SetNonblocking(true, s);
		Attach(s);
	}
}
开发者ID:f059074251,项目名称:interested,代码行数:31,代码来源:UdpSocket.cpp

示例3: CreateSocket

int EgSock::Connect(const char* ip, uint16_t port, function<void(sp_EgSock)> callback) 
{
	_fd = CreateSocket();
	SetNonblock(fd);
	SetNodelay(fd);

	_peer_ip = ip;
	_port = port;
	_state = EG_SOCK_CONNECTING;
	_callback = callback;

	sockaddr_in serv_addr;
	SetAddr(ip, port,  &serv_addr);
	if (connect(_fd, (sockaddr*)&serv_addr, sizeof(serv_addr)) == SOCKET_ERROR) {
		if (!((errno == EINPROGRESS) || (errno == EWOULDBLOCK))) {
			loge("connect failed, err_code=%d", errno);
			close(_fd);
			throw egex("connect failed, errno=%d", errno);
		}
	} else {
		_state = EG_SOCK_CONNECTED;
		callback(shared_from_this());
	}
	return _fd;
}
开发者ID:narychen,项目名称:eg,代码行数:25,代码来源:EgSock.cpp

示例4: Listen

int CLS_TCPSvr::Listen()
{
    char *strIP;

    if(m_iStatus==SS_UNUSED)
        if(CreateSocket()<0)
            return -1;

    if(m_iStatus!=SS_LISTEN)
    {
        if(m_iStatus!=SS_BOUND)
            if(Bind()<0)
                return -2;

        if (listen(m_iSocket, 5)<0) 
        {
            CloseSocket();
            return -3;
        }

        if(!m_iLocalPort)
        {
            strIP=GetLocalHost(&m_iLocalPort);
            if(strIP)
                strcpy(m_strLocalIP, strIP);
        }

        m_iStatus=SS_LISTEN;
    }

    return 0;
}
开发者ID:cocti-zhonghao,项目名称:fj_callSign,代码行数:32,代码来源:cls_sock.cpp

示例5: SendData

//  Write a socket
wxInt32 BufferedSocket::SendData(const wxInt32 &Timeout)
{   
    wxInt32 BytesSent;
    
    if (CreateSocket() == false)
        return 0;

    // clear it
    memset(m_SendBuffer, 0, MAX_PAYLOAD);
    
    // copy data
    size_t WrittenSize = m_SendBufferHandler->CopyTo(m_SendBuffer, 
                                                      MAX_PAYLOAD);

    // Creation of this will start the stop watch
    wxStopWatch sw;
                
    // send the data
    BytesSent = send(m_Socket, (const char *)m_SendBuffer, WrittenSize, 0);

    // set the start ping
    m_SendPing = sw.Time();
    
    CheckError();    
        
    // return the amount of bytes sent
    return BytesSent;
}
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:29,代码来源:net_io.cpp

示例6: CreateSocket

nsresult
KeyStoreConnector::CreateListenSocket(struct sockaddr* aAddress,
                                      socklen_t* aAddressLength,
                                      int& aListenFd)
{
  ScopedClose fd;

  nsresult rv = CreateSocket(fd.rwget());
  if (NS_FAILED(rv)) {
    return rv;
  }
  rv = SetSocketFlags(fd);
  if (NS_FAILED(rv)) {
    return rv;
  }
  if (aAddress && aAddressLength) {
    rv = CreateAddress(*aAddress, *aAddressLength);
    if (NS_FAILED(rv)) {
      return rv;
    }
  }

  // Allow access for wpa_supplicant (different user, different group)
  //
  // TODO: Improve this by setting specific user/group for
  //       wpa_supplicant by calling |fchmod| and |fchown|.
  //
  chmod(KEYSTORE_SOCKET_PATH, S_IRUSR|S_IWUSR|
                              S_IRGRP|S_IWGRP|
                              S_IROTH|S_IWOTH);

  aListenFd = fd.forget();

  return NS_OK;
}
开发者ID:MekliCZ,项目名称:positron,代码行数:35,代码来源:KeyStoreConnector.cpp

示例7: memccpy

int Client::Run(const char* pIP, unsigned short uPort, const char * pFileName)
{
    int iRet = 0;
    if (pIP == NULL)
    {
        iRet = -1;
        return iRet;
    }
    memccpy(m_sIPAddress, pIP, 0, sizeof(m_sIPAddress) - 1);
    m_sIPAddress[sizeof(m_sIPAddress) - 1] = 0;
    m_uPort = uPort;
    if (pFileName != NULL) {
        m_RequireType = 2; //File
        memccpy(m_sFilename, pFileName, 0, sizeof(m_sFilename) - 1);
        m_sFilename[sizeof(m_sFilename) - 1] = 0;
    }
    else
    {
        m_RequireType = 1; //DIR
    }

    CreateSocket();
    ConnectSocket();
    return iRet;
}
开发者ID:hank-sunday,项目名称:DataHub-Daemon,代码行数:25,代码来源:DataClient.cpp

示例8: BindCompletionPort

DWORD CEgTcpDriver::CreateAcceptSocket(BOOL bBindIocp)
{
    DWORD       dwRecvNumBytes = 0;     
	DWORD		dwRes;

    if (bBindIocp)
    {
		m_ListenSocketContext.m_ConnectioID.m_Socket = m_ListenSocket;
		m_ListenSocketContext.m_pIOContext.m_IoOperation = ClientIoAccept;
        dwRes = BindCompletionPort(m_ListenSocketContext);
        if (dwRes != 0)
            return dwRes;
    }

    m_ListenSocketContext.m_pIOContext.m_SocketAccept = CreateSocket();
    if (INVALID_SOCKET == m_ListenSocketContext.m_pIOContext.m_SocketAccept)
        return WSAGetLastError();

    int nRet = AcceptEx(
            m_ListenSocket, 
            m_ListenSocketContext.m_pIOContext.m_SocketAccept,
            (LPVOID)(m_ListenSocketContext.m_pIOContext.m_ReceiveBuffer.buf),
            0,
            sizeof(SOCKADDR_IN) + 16,
            sizeof(SOCKADDR_IN) + 16,
            &dwRecvNumBytes,
            (LPOVERLAPPED) &(m_ListenSocketContext.m_pIOContext.m_SendOverlapped)
            );
    if (nRet == SOCKET_ERROR && (ERROR_IO_PENDING != WSAGetLastError())) 
		return WSAGetLastError();

	return 0;
}
开发者ID:AlexS2172,项目名称:IVRMstandard,代码行数:33,代码来源:egtcpdriver.cpp

示例9: Bind

	virtual bool	Bind( const CIPAddr *pAddr )
	{
		if ( !CreateSocket() )
			return false;
    
		return BindPart2( pAddr );
	}
开发者ID:RaisingTheDerp,项目名称:raisingthebar,代码行数:7,代码来源:iphelpers.cpp

示例10: CreateSocket

DWORD WINAPI CEgTcpDriver::CreateListenSocket()
{
    SOCKADDR_IN si_addrlocal;
    int         nRet;
    LINGER      lingerStruct;

    lingerStruct.l_onoff = 0;
    lingerStruct.l_linger = 0;

    m_ListenSocket = CreateSocket();
    if (INVALID_SOCKET == m_ListenSocket)
        return WSAGetLastError();

    si_addrlocal.sin_family = AF_INET;
    si_addrlocal.sin_port = htons(m_usServerPort);
    si_addrlocal.sin_addr.s_addr = htonl(INADDR_ANY);       
    nRet = bind(m_ListenSocket, (struct sockaddr *)&si_addrlocal, sizeof(si_addrlocal));

    if (SOCKET_ERROR == nRet) 
        return WSAGetLastError();

    nRet = listen(m_ListenSocket, SOMAXCONN);
    if (SOCKET_ERROR == nRet) 
        return WSAGetLastError();
    
	return 0;
}
开发者ID:AlexS2172,项目名称:IVRMstandard,代码行数:27,代码来源:egtcpdriver.cpp

示例11: PortTransfer_1

BOOL PortTransfer_1(WORD ListenPort, char *szIP, WORD wPort)
{
 HANDLE hThread;
 DWORD dwThreadId;
 SOCKET AcceptSocket;
 TransferParam<ADDRESS, SOCKET> ConfigInfo;
 _snprintf(ConfigInfo.GlobalData.szIP, ADDRSIZE, "%s", szIP);
 ConfigInfo.GlobalData.wPort = wPort;
 //监听个服务端口,即映射端口
 SOCKET localsockid = CreateSocket(INADDR_ANY, ListenPort);
 if(localsockid <= 0)
 goto error;
 while(1)
 {
  printf("Accepting new Client...");
  AcceptSocket = accept(localsockid, NULL, NULL);
  if(AcceptSocket == INVALID_SOCKET)
   goto error;
  nTimes++;
  printf("OK.\r\n");
  //将接受到的客户请求套接字转到新的线程里处理
  //然后继续等待新的请求
  ConfigInfo.LocalData.Push(AcceptSocket);
  hThread = CreateThread(NULL, 0, PortTransfer_1, (LPVOID)&ConfigInfo, NULL, &dwThreadId);
  if(hThread)
   CloseHandle(hThread);
  else
   Sleep(1000);
 }
error:
 printf("Error.\r\n");
 closesocket(localsockid);
 return false;
}
开发者ID:GeeksRoad,项目名称:MyProxy,代码行数:34,代码来源:protfword_demo.c

示例12: CreateSocket

void SocketEngine::sendData(const char* data)
{
    if (m_socket==NULL) {
        CreateSocket();
    }
    
    if (m_socket==NULL) {
        cout<<"Socket创建失败"<<endl;
        return;
    }
    
    try {
    cocos2d::CCLog("send() datas : %s \n\n",data);
    m_socket->SendData(data, strlen(data)+1);
    }catch (SocketException &excep) {

        cout<<"收到参数意外"<<endl;

        cocos2d::CCLog("sendData recvDatas Error: %s \n\n",(const char*)excep);

        return;
    }
    
//    strcpy(outData, data);
    cout<<"开始线程接受Socket数据"<<endl;
    if(pthread_create(&pthead_rec, NULL, reciveData, this)!=0){
        
        //pthead_recx线程标示,reciveData回调函数, m_socket传入的参数
        

        cout<<"创建reciveData失败"<<endl;
        
    }
    
}
开发者ID:wwb0709,项目名称:feichuan,代码行数:35,代码来源:SocketEngine.cpp

示例13: Attach

int UdpSocket::Bind(SocketAddress& ad, int range)
{
	if (GetSocket() == INVALID_SOCKET)
	{
		Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp"));
	}
	if (GetSocket() != INVALID_SOCKET)
	{
		SetNonblocking(true);
		int n = bind(GetSocket(), ad, ad);
		int tries = range;
		while (n == -1 && tries--)
		{
			ad.SetPort(ad.GetPort() + 1);
			n = bind(GetSocket(), ad, ad);
		}
		if (n == -1)
		{
			Handler().LogError(this, "bind", Errno, StrError(Errno), LOG_LEVEL_FATAL);
			SetCloseAndDelete();
#ifdef ENABLE_EXCEPTIONS
			throw Exception("bind() failed for UdpSocket, port:range: " + Utility::l2string(ad.GetPort()) + ":" + Utility::l2string(range));
#endif
			return -1;
		}
		m_bind_ok = true;
		m_port = ad.GetPort();
		return 0;
	}
	return -1;
}
开发者ID:f059074251,项目名称:interested,代码行数:31,代码来源:UdpSocket.cpp

示例14: main

int 
main(int argc, char *argv[])
{
    if (argc != 3)
    {
        printf("%s serverhost serverport\n", argv[0]);
        exit(0);
    }
    // get the server host info
    //
    int serverport = atoi(argv[2]);
    int err;
    struct hostent hp;
    char buf[1024];
    unsigned long hostAddr = 0;

    if((gethostbyname_r(argv[1], &hp, buf, sizeof(buf), &err) == NULL))
    {
        printf("unable to resolve host address(%s)\n", argv[1]);
        exit(0);
    }
    hostAddr = ((struct in_addr*)hp.h_addr)->s_addr;

    while (1)
    {
        // Create the socket
        //
        CreateSocket(hostAddr, serverport);
    
    }
}
开发者ID:pp7462-git,项目名称:sandbox,代码行数:31,代码来源:telnetloop.cpp

示例15: CreateSocket

int SocketInfo::Create(const std::string& context) const {
    auto types = android::base::Split(type(), "+");
    int flags =
        ((types[0] == "stream" ? SOCK_STREAM : (types[0] == "dgram" ? SOCK_DGRAM : SOCK_SEQPACKET)));
    bool passcred = types.size() > 1 && types[1] == "passcred";
    return CreateSocket(name().c_str(), flags, passcred, perm(), uid(), gid(), context.c_str());
}
开发者ID:MoKee,项目名称:android_system_core,代码行数:7,代码来源:descriptors.cpp


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