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


C++ SocketClient类代码示例

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


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

示例1: pthread_mutex_lock

void SocketListener1::sendData(const void *data, int len) {
  SocketClientCollection safeList;

  /* Add all active clients to the safe list first */
  safeList.clear();
  pthread_mutex_lock(&mClientsLock);
  SocketClientCollection::iterator i;

  for (i = mClients->begin(); i != mClients->end(); ++i) {
    SocketClient* c = *i;
    c->incRef();
    safeList.push_back(c);
  }
  pthread_mutex_unlock(&mClientsLock);

  while (!safeList.empty()) {
    /* Pop the first item from the list */
    i = safeList.begin();
    SocketClient* c = *i;
    safeList.erase(i);
    if (c->sendData(data, len)) {
      ALOGW("Error sending data (%s)", strerror(errno));
    }
    c->decRef();
    // Release socket client on socket disconnect
    if (errno == EPIPE) {
      ALOGW("Socket disconnect; closing");
      release(c, false);
    }
  }
}
开发者ID:kumarrishav,项目名称:silk,代码行数:31,代码来源:SocketListener1.cpp

示例2: methodPost

bool HttpServer::methodPost(const SocketClient &client) {
	std::string content;
	if (StringConverter::getContentFrom(client.getMessage(), content)) {
		std::string file;
		if (StringConverter::getRequestedFile(client.getMessage(), file)) {
			if (file.compare("/data.xml") == 0) {
				// not used yet
			} else if (file.compare("/streams.xml") == 0) {
				_streams.fromXML(content);
			} else if (file.compare("/config.xml") == 0) {
				_properties.fromXML(content);
#ifdef LIBDVBCSA
			} else if (file.compare("/dvbapi.xml") == 0) {
				_streams.getDecrypt()->fromXML(content);
#endif
			}
		}
	}
	// setup reply
	std::string htmlBody;
	getHtmlBodyWithContent(htmlBody, HTML_NO_RESPONSE, "", CONTENT_TYPE_HTML, 0, 0);

	// send 'htmlBody' to client
	if (send(client.getFD(), htmlBody.c_str(), htmlBody.size(), 0) == -1) {
		PERROR("send htmlBody");
		return false;
	}
	return true;
}
开发者ID:arn354,项目名称:SATPI,代码行数:29,代码来源:HttpServer.cpp

示例3: select

inline
int
SocketRegistry<T>::syncPerformReceive(char * host,
                                      T & t,
                                      Uint32 timeOutMillis) {
    char buf[255] ; //temp. just for testing. must fix better
    struct timeval timeout;
    timeout.tv_sec  = timeOutMillis / 1000;
    timeout.tv_usec = (timeOutMillis % 1000) * 1000;
    int reply;
    SocketClient * sc;
    for(Uint32 i=0; i < m_nSocketClients; i++) {
        sc = m_socketClients[i];
        if(strcmp(sc->gethostname(), remotehost)==0) {
            if(sc->isConnected()) {
                FD_ZERO(&tcpReadset);
                reply = select(sc->getSocket(), &tcpReadset, 0, 0, &timeout);
                if(reply > 0) {
                    return t->runSession(sc->getSocket(), t);
                }
            }

        }
    }
    return 0;
}
开发者ID:fengshao0907,项目名称:TMySQL,代码行数:26,代码来源:SocketRegistry.cpp

示例4: pthread_mutex_lock

void SocketListener::sendBroadcast(int code, const char *msg, bool addErrno) {
    SocketClientCollection safeList;

    /* Add all active clients to the safe list first */
    safeList.clear();
    pthread_mutex_lock(&mClientsLock);
    SocketClientCollection::iterator i;

    for (i = mClients->begin(); i != mClients->end(); ++i) {
        SocketClient* c = *i;
        c->incRef();
        safeList.push_back(c);
    }
    pthread_mutex_unlock(&mClientsLock);

    while (!safeList.empty()) {
        /* Pop the first item from the list */
        i = safeList.begin();
        SocketClient* c = *i;
        safeList.erase(i);
        // broadcasts are unsolicited and should not include a cmd number
        if (c->sendMsg(code, msg, addErrno, false)) {
            SLOGW("Error sending broadcast (%s)", strerror(errno));
        }
        c->decRef();
    }
}
开发者ID:LedoInteractive,项目名称:platform_system_core,代码行数:27,代码来源:SocketListener.cpp

示例5: trace_log

/**< 跟第三方系统进行通信 */
int CTradeBase::DoSendAndRcv(unsigned char *ReqBuf, int ReqLen,unsigned char *RepBuf, int *RepLen, int TimeOut,char* errDesc)
{
    trace_log(DBG, "SndBuf len:%d",ReqLen);
    trace_mem(ReqBuf, ReqLen);
    SocketClient client;
    return client.SendToHost(ReqBuf,ReqLen,RepBuf,*RepLen,g_Cfg.CupHost.cIp,g_Cfg.CupHost.iPort,40,errDesc);
}
开发者ID:vagabond1132,项目名称:Code,代码行数:8,代码来源:tradebase.cpp

示例6: dataCallback

void SocketClient::dataCallback(int, unsigned int flags, void* userData)
{
    SocketClient* client = reinterpret_cast<SocketClient*>(userData);
    if (flags & EventLoop::Read)
        client->readMore();
    if (flags & EventLoop::Write)
        client->writeMore();
}
开发者ID:Andersbakken,项目名称:diff,代码行数:8,代码来源:SocketClient.cpp

示例7: WorkerThread

DWORD WINAPI ClientIOCP::WorkerThread(LPVOID lpObject)
{
	SocketClient client;
	char* reply;

	int res = client.Connect(8085);
	client.Send("This is a test\n", reply);
	return 1;
}
开发者ID:MagnusTiberius,项目名称:iocphttpd,代码行数:9,代码来源:ClientIOCP.cpp

示例8: FD_ZERO

inline
int 
SocketRegistry<T>::pollSocketClients(Uint32 timeOutMillis) {



  // Return directly if there are no TCP transporters configured
  if (m_nSocketClients == 0){
    tcpReadSelectReply = 0;
    return 0;
  }
  struct timeval timeout;
  timeout.tv_sec  = timeOutMillis / 1000;
  timeout.tv_usec = (timeOutMillis % 1000) * 1000;


  NDB_SOCKET_TYPE maxSocketValue = 0;
  
  // Needed for TCP/IP connections
  // The read- and writeset are used by select
  
  FD_ZERO(&tcpReadset);

  // Prepare for sending and receiving
  for (Uint32 i = 0; i < m_nSocketClients; i++) {
    SocketClient * t = m_socketClients[i];
    
    // If the socketclient is connected
    if (t->isConnected()) {
      
      const NDB_SOCKET_TYPE socket = t->getSocket();
      // Find the highest socket value. It will be used by select
      if (socket > maxSocketValue)
	maxSocketValue = socket;
      
      // Put the connected transporters in the socket read-set 
      FD_SET(socket, &tcpReadset);
    }
  }
  
  // The highest socket value plus one
  maxSocketValue++; 
  
  tcpReadSelectReply = select(maxSocketValue, &tcpReadset, 0, 0, &timeout);  
#ifdef NDB_WIN32
  if(tcpReadSelectReply == SOCKET_ERROR)
  {
    NdbSleep_MilliSleep(timeOutMillis);
  }
#endif

  return tcpReadSelectReply;

}
开发者ID:SunguckLee,项目名称:MariaDB,代码行数:54,代码来源:SocketRegistry.hpp

示例9: trace_log

/**< 跟第三方系统进行通信 */
int CTradeBase::DoSendAndRcv(unsigned char *ReqBuf, int ReqLen,unsigned char *RepBuf, int *RepLen, int TimeOut,char* errDesc)
{
    trace_log(DBG, "SndBuf len:%d",ReqLen);
    trace_mem(ReqBuf, ReqLen);
#ifndef USE_LONG_CONN
    SocketClient client;
    return client.SendToHost(ReqBuf,ReqLen,RepBuf,*RepLen,g_Cfg.CupHost[0].Host,g_Cfg.CupHost[0].Port,40,errDesc);
#else
	return 0;
#endif
}
开发者ID:vagabond1132,项目名称:Code,代码行数:12,代码来源:tradebase.cpp

示例10: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	SocketClient so = SocketClient("192.168.0.179");
	so.sendTo("Hello from C++  111");
	so.sendTo("Hello from C++  222");
	so.~SocketClient();

	/*WSAData data;
	SOCKET sock;
	struct sockaddr_in si_other;
	const std::string address = "192.168.0.179";
	int slen = sizeof(si_other);
	char message[512] = "Hello World Java, I am a C++ Client Socket";

	int ret = WSAStartup(MAKEWORD(2, 2), &data);
	if (ret != 0) {
		printf("Error WSAStartup failed: " + WSAGetLastError());
		WSACleanup();
	}

	sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (sock == INVALID_SOCKET) {
		printf("Error opening socket: " + WSAGetLastError());
	}

	memset((char *)&si_other, 0, sizeof(si_other));
	si_other.sin_family = AF_INET;
	si_other.sin_port = htons(8881);
	si_other.sin_addr.S_un.S_addr = inet_addr(address.c_str());
	
	std::stringstream sstm;
	for (int i = 0; i < 10; i++) {
		sstm << "Attemp #" << i << " - Sending:" << message << "\n";
		printf(sstm.str().c_str());
		ret = sendto(sock, message, strlen(message), 0, (struct sockaddr *) &si_other, slen);
		if (ret < 0) {
			sstm << "Failed Sending:" << WSAGetLastError();
		}
		sstm.str("");
	}

	printf("\n *** End ***");
	std::getchar();
	exit(0);

	closesocket(sock);
	WSACleanup();  */

	return 0;
}
开发者ID:ualter,项目名称:CCSocketSample,代码行数:50,代码来源:SocketClientConsoleApp.cpp

示例11:

bool
SocketRegistry<T>::reconnect(const char * host) {
    for(Uint32 i=0; i < m_nSocketClients; i++) {
        SocketClient * socketClient = m_socketClients[i];
        if(strcmp(socketClient->gethostname(), host)==0) {
            if(!socketClient->isConnected()) {
                if(socketClient->openSocket() > 0)
                    return true;
                else return false;
            }
        }
    }
    return false;
}
开发者ID:fengshao0907,项目名称:TMySQL,代码行数:14,代码来源:SocketRegistry.cpp

示例12:

inline
bool 
SocketRegistry<T>::removeSocketClient(const char * host){
  for(Uint32 i=0; i < m_nSocketClients; i++) {
    SocketClient * socketClient = m_socketClients[i];
    if(strcmp(socketClient->gethostname(), host)==0) {
      if(!socketClient->isConnected()) {
	if(socketClient->closeSocket() > 0) {
	  delete socketClient;
	  return true;
	}
	else return false;
      }
    }
  }
  return false;
}
开发者ID:SunguckLee,项目名称:MariaDB,代码行数:17,代码来源:SocketRegistry.hpp

示例13: sendFacialExpressionAnimation

void sendFacialExpressionAnimation(SocketClient& sock, EmoStateHandle eState) {

	std::ostringstream output;

    IEE_FacialExpressionAlgo_t upperFaceType =
                            IS_FacialExpressionGetUpperFaceAction(eState);
    IEE_FacialExpressionAlgo_t lowerFaceType =
                            IS_FacialExpressionGetLowerFaceAction(eState);

	float upperFaceAmp = IS_FacialExpressionGetUpperFaceActionPower(eState);
	float lowerFaceAmp = IS_FacialExpressionGetLowerFaceActionPower(eState);

	if (IS_FacialExpressionIsBlink(eState)) {
		output << "B,";
	}

	if (IS_FacialExpressionIsLeftWink(eState)) {
		output << "l,";
	}

	if (IS_FacialExpressionIsRightWink(eState)) {
		output << "r,";
	}


	if (upperFaceAmp > 0.0) {
		switch (upperFaceType) {
			case FE_SURPRISE:	output << "b";	break;
			case FE_FROWN:    output << "f";  break;
			default:			break;
		}
		output << numberToString(static_cast<int>(upperFaceAmp*100.0f)) << ",";
	}

	if (lowerFaceAmp > 0.0) {
		switch (lowerFaceType) {
			case FE_CLENCH:	output << "G";	break;
			case FE_SMILE:		output << "S";	break;
			default:			break;
		}
		output << numberToString(static_cast<int>(lowerFaceAmp*100.0f)) << ",";
	}

	std::string outString = output.str();

	// Remove the last comma
	if (outString.length()) {
		outString.resize(outString.length()-1);
	}

	if (!outString.length()) {
		outString = std::string("neutral");
	}

	sock.SendBytes(outString);
}
开发者ID:kcrowley1,项目名称:community-sdk,代码行数:56,代码来源:FacialExpressionDemo.cpp

示例14: memcpy

/**************************************************************
函数名称: GetDataFromHsm
函数功能: 连接加密机从其获取数据
入口参数: pMsgBuffer[in/out]:发送或返回的数据中的MSG
           iLen[in/out]:发送或返回数据的长度
相关调用:
返 回 值: true成功, false失败
**************************************************************/
bool EnCryptComm::GetDataFromHsm(unsigned char *pMsgBuffer, unsigned & iLen)
{
    unsigned char cmd = pMsgBuffer[0], Buffer[1024]={0};
    unsigned sLen;//发送数据长度
    sLen = iLen + 7;
    memcpy(Buffer, &sLen, 2);//LC
    Buffer[2]=0xF1;//INS
    Buffer[3]=0;//SEQ
    //CR默认为0
    memcpy(&Buffer[6], pMsgBuffer, iLen);//MSG
    Buffer[sLen-1] = CalcSum(Buffer, sLen - 1);//CRC
    char errDesc[512]={0};
    unsigned char cRecBuf[1024]={0};
    int recLen=0;
    SocketClient client;
    int iErrorCode=client.SendToHost(Buffer,sLen,cRecBuf,recLen,g_Cfg.EncHost.Host, g_Cfg.EncHost.Port,20,errDesc);
    if(0==iErrorCode)
    {
    	trace_log(DBG, "recv from enchost");
		trace_mem(cRecBuf, recLen);
        if(cRecBuf[recLen-1] == CalcSum(cRecBuf, recLen - 1) && cRecBuf[6] == cmd && cRecBuf[8] == CMD_OK)
        {//校验值正确,与原命令字相同,返回码为成功
            if(memcmp(pMsgBuffer+2, cRecBuf+9, LEN_MERCHNO+LEN_TERMINO)!=0)//+LEN_TERMINO
            {//比较商户号与终端号
                trace_log(DBG, "The return data from encryptor is not match!!");
                return false;
            }
            memcpy(pMsgBuffer, cRecBuf+6, recLen-7);//去掉LC,INS,SEQ,CR,CRC
            iLen = recLen-7;
            trace_log(DBG,"GetDataFromHsm->iLen=%d",iLen);
            return true;
        }
        else
        {
            trace_log(ERR, "GetDataFromHsm else CalcSum  %d", recLen);
            return false ;
        }
    }else{
        trace_log(ERR,errDesc);
        return false;
    }
}
开发者ID:vagabond1132,项目名称:Code,代码行数:50,代码来源:encryptcomm.cpp

示例15: recv

void *SocketClient::ReceiveThread(void *para) {
	SocketClient *socketClient = (SocketClient *) para;
	int res;
	while (1) {
		res = recv(socketClient->clientSockFd, socketClient->recvMessage, BUFFER_SIZE, 0);
		if (res == 0) {
			close(socketClient->clientSockFd);
			socketClient->clientSockFd = -1;
			socketClient->pUpdateStauts(Disconnected);
			break;
		}else if(res > 0){
			socketClient->pUpdateMessage(socketClient->recvMessage, res);
		}else{
			perror("receive error");
		}

	}
	printf("Server Closed\n");
	return 0;
}
开发者ID:Bing0,项目名称:SocketClient,代码行数:20,代码来源:SocketClient.cpp


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