本文整理汇总了C++中CSocket::bind方法的典型用法代码示例。如果您正苦于以下问题:C++ CSocket::bind方法的具体用法?C++ CSocket::bind怎么用?C++ CSocket::bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSocket
的用法示例。
在下文中一共展示了CSocket::bind方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void CDebug::run() {
if ( m_port==DBG_USB ) {
//
// USB port
//
CSerial cdc(USB);
m_shell.assign(cdc);
while(1) {
if ( cdc.isConnected() ) {
m_shell.run();
}
}
} else {
//
// Telnet (TCP/IP port 23)
//
CSocket server;
CSocket *client;
server.create(SOCK_STREAM);
server.bind(TELNET_PORT);
server.listen();
while (1) {
if ((client = server.accept()) != NULL) {
client->keepAlive(3, 3, 3); // set keep alive in 3 seconds for idle, try in 3 seconds and 3 times
m_shell.assign(client);
m_shell.run();
delete client;
}
}
}
}
示例2: main
/* ==============================================
main task routine
============================================== */
int main(void) {
pool_memadd((uint32_t)pool, sizeof(pool));
#ifdef DEBUG
dbg.start();
#endif
char ch;
CSocket *client;
CSocket server;
server.create(SOCK_STREAM);
server.bind(23); // bind to port 23
server.listen(); // enter listen mode
// Enter an endless loop
while(1){
client = server.accept(); // accept and create a connected socket
if ( client!=NULL ) {
dbg.println("Client connected\n");
while( client->isConnected() ) { // check connection
if ( client->read(&ch, sizeof(ch)) ) { // read from client
client->write(&ch, sizeof(ch)); // echo to client
}
}
dbg.println("Client disconnected\n");
delete client; // free client after disconnected
}
}
return 0 ;
}
示例3:
void CPecaCore::threadServer()
{
CPecaServer server;
CSocket sockServer;
sockServer.bind();
while (1) {
CSocket* psock = sockServer.accept();
if (psock) {
char strIP[64];
psock->GetFromHost().toStr(strIP);
LOG_DEBUG(_T("%s から接続要求"), strIP);
boost::thread(boost::bind(&CPecaCore::handshake, this, psock));
}
::Sleep(10);
}
//server.
}