本文整理汇总了C++中TcpServer类的典型用法代码示例。如果您正苦于以下问题:C++ TcpServer类的具体用法?C++ TcpServer怎么用?C++ TcpServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TcpServer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: fakeMessagePassing
// Message passing routine, used to send and receive a typed message
// Useful for checking the packing and unpacking of message data.
void fakeMessagePassing(TypedMessage &send, TypedMessage &recv)
{
const int tcpPort = TEST_PORT_BASE+401;
char ipAddr[] = "127.0.0.1";
TcpClient tcpClient;
TcpServer tcpServer;
SimpleMessage msgSend, msgRecv;
send.toTopic(msgSend);
// Construct server
tcpServer.init(tcpPort);
// Construct a client
tcpClient.init(&ipAddr[0], tcpPort);
tcpClient.makeConnect(); // make tcp client connection
tcpServer.makeConnect(); // make tcp server connection
tcpClient.sendMsg(msgSend); // send message
tcpServer.receiveMsg(msgRecv); // physically receive message
recv.init(msgRecv); // copy received message into reference
}
开发者ID:usnistgov,项目名称:el-robotics-core,代码行数:27,代码来源:rosthread.cpp
示例2: main
int main(int argc, char* argv[])
{
// Create an instance of the server
TcpServer server = TcpServer::create_server();
// Prepare the server for listening for client connections
char* port_str = (char*) "2013"; // default port 2013
if (argc == 2) {
port_str = (char*) argv[1];
}
unsigned short port = (unsigned short) atoi(port_str);
int server_fd = server.prepare_server_socket(port, SOCK_STREAM);
if (server_fd == -1) {
cout << "Server preparation failed. Exiting application..." << endl;
exit(1);
}
// Run the main loop
// This method run indefinitely
int ret = server.run_main_event_loop();
if (ret != 0) {
cout << "Error running the server main event loop, exiting the server process..." << endl;
}
// At this point we are exiting the server
return 0;
}
开发者ID:bilash,项目名称:NonblockingTcpServer,代码行数:28,代码来源:tcp_server_test.cpp
示例3: Q_ASSERT
void Client::connectToServer(LoginHandler *loginhandler)
{
Q_ASSERT(_isloopback);
TcpServer *server = new TcpServer(this);
_server = server;
_isloopback = false;
m_sessionId = loginhandler->sessionId(); // target host/join ID (if known already)
connect(server, SIGNAL(loggingOut()), this, SIGNAL(serverDisconnecting()));
connect(server, SIGNAL(serverDisconnected(QString, QString, bool)), this, SLOT(handleDisconnect(QString, QString, bool)));
connect(server, SIGNAL(serverDisconnected(QString, QString, bool)), loginhandler, SLOT(serverDisconnected()));
connect(server, SIGNAL(loggedIn(QString, int, bool)), this, SLOT(handleConnect(QString, int, bool)));
connect(server, SIGNAL(messageReceived(protocol::MessagePtr)), this, SLOT(handleMessage(protocol::MessagePtr)));
connect(server, SIGNAL(expectingBytes(int)), this, SIGNAL(expectingBytes(int)));
connect(server, SIGNAL(bytesReceived(int)), this, SIGNAL(bytesReceived(int)));
connect(server, SIGNAL(bytesSent(int)), this, SIGNAL(bytesSent(int)));
connect(server, SIGNAL(lagMeasured(qint64)), this, SIGNAL(lagMeasured(qint64)));
if(loginhandler->mode() == LoginHandler::HOST)
loginhandler->setUserId(m_myId);
emit serverConnected(loginhandler->url().host(), loginhandler->url().port());
server->login(loginhandler);
m_lastToolCtx = canvas::ToolContext();
}
开发者ID:Xiangyu-Xue,项目名称:Drawpile,代码行数:28,代码来源:client.cpp
示例4: main
int main(int argc, char** argv)
{
// Initialize ROS node "sm_talker"
ros::init(argc, argv, "sm_listener");
// Required to start timers for non-node ROS use.
ros::Time::init();
// Little message to know she's started
ROS_INFO_STREAM("STARTING SM_MANAGER");
// Create and execute manager
// * Create a TCP server connection on TCP_PORT (see common.h)
// * Initialize manager using server connection
// * Initialize handler using server connection
// * Add handler to manager
// * Execute manager spin loop
TcpServer server;
server.init(TCP_PORT);
MessageManager manager;
MyHandler handler;
manager.init(&server);
// Handler initilaized with reply connection (typically the same as
// incoming connection but now always)
handler.init(&server);
manager.add(&handler);
manager.spin();
return 0;
}
开发者ID:drchrislewis,项目名称:industrial_training,代码行数:33,代码来源:sm_manager.cpp
示例5: while
void* TcpServer::receiveThreadFunction(void* arg){
TcpServer* server = (TcpServer*)arg;
while(server->initialized){
printf("TcpServer: listening for new connection\n");
struct sockaddr_in client_addr;
socklen_t client_addr_len = sizeof(client_addr);
server->client_fd = accept(server->socket_fd, (struct sockaddr*)&client_addr, &client_addr_len);
if (server->client_fd < 0){
perror("TcpServer Error: accept");
server->initialized = false;
return 0;
}
printf("TcpServer: connection accepted\n");
server->connected = true;
while(server->isConnected()){
server->receivePacket();
}
printf("TcpServer: connection closed\n");
}
return 0;
}
开发者ID:awandzel,项目名称:Domains-LegoMindstorms,代码行数:26,代码来源:TcpServer.cpp
示例6: listen
void InetWvIn :: listen( int port, unsigned int nChannels,
Stk::StkFormat format, Socket::ProtocolType protocol )
{
mutex_.lock();
if ( connected_ ) delete soket_;
if ( nChannels < 1 ) {
oStream_ << "InetWvIn()::listen(): the channel argument must be greater than zero.";
handleError( StkError::FUNCTION_ARGUMENT );
}
if ( format == STK_SINT16 ) dataBytes_ = 2;
else if ( format == STK_SINT32 || format == STK_FLOAT32 ) dataBytes_ = 4;
else if ( format == STK_FLOAT64 ) dataBytes_ = 8;
else if ( format == STK_SINT8 ) dataBytes_ = 1;
else {
oStream_ << "InetWvIn(): unknown data type specified!";
handleError( StkError::FUNCTION_ARGUMENT );
}
dataType_ = format;
unsigned long bufferBytes = bufferFrames_ * nBuffers_ * nChannels * dataBytes_;
if ( bufferBytes > bufferBytes_ ) {
if ( buffer_) delete [] buffer_;
buffer_ = (char *) new char[ bufferBytes ];
bufferBytes_ = bufferBytes;
}
data_.resize( bufferFrames_, nChannels );
lastFrame_.resize( 1, nChannels, 0.0 );
bufferCounter_ = 0;
writePoint_ = 0;
readPoint_ = 0;
bytesFilled_ = 0;
if ( protocol == Socket::PROTO_TCP ) {
TcpServer *socket = new TcpServer( port );
oStream_ << "InetWvIn:listen(): waiting for TCP connection on port " << socket->port() << " ... ";
handleError( StkError::STATUS );
fd_ = socket->accept();
if ( fd_ < 0) {
oStream_ << "InetWvIn::listen(): Error accepting TCP connection request!";
handleError( StkError::PROCESS_SOCKET );
}
oStream_ << "InetWvIn::listen(): TCP socket connection made!";
handleError( StkError::STATUS );
soket_ = (Socket *) socket;
}
else {
soket_ = new UdpSocket( port );
fd_ = soket_->id();
}
connected_ = true;
mutex_.unlock();
}
开发者ID:ilearain,项目名称:stk,代码行数:59,代码来源:InetWvIn.cpp
示例7: gvLog
void* TcpServer::RecvParse(void* pData)
{
TcpServer* pthis = NULL;
mio2_t m = NULL;
LPMESSAGE_DATA pMsg = NULL;
int iLen = 0;
if (pData) {
m = ((c2s_t)pData)->mio2;
pthis = (TcpServer*)(((c2s_t)pData)->pvoid);
}
if (!pthis || !m) {
gvLog(LOG_ERR_SYS, "(TcpServer::RecvParse) receive pool start fail by error param");
return NULL;
}
RecvParser* pRecvParser = new RecvParser();
if (!pRecvParser) return NULL;
LPMESSAGE_DATA pErrMsgData = NULL;
while (pthis->IsRunning()) {
pMsg = g_MsgListRecv->Get_Msg();
if (pMsg) {
gvLog(LOG_MSG, "(TcpServer::RecvParse) entering receive parser... iFd:%d", pMsg->iFd);
iLen = pRecvParser->ParserData(pMsg);
gvLog(LOG_MSG, "(TcpServer::RecvParse) MSG: iLen:%d iFd:%d", iLen, pMsg->iFd);
if (iLen > 0) {
//put into data parser
pthis->AddConnect();
pMsg = MatchPacketHandler::GetInstance()->Handling(pMsg, pErrMsgData);
if (NULL != pMsg){
g_MsgListData->Put_Msg(pMsg);
}
else if (NULL != pErrMsgData){
pErrMsgData->bSendAndClose = true;
g_MsgListSnd->Put_Msg(pErrMsgData);
}
else {
if (NULL != pMsg) {
gvLog(LOG_MSG, "(TcpServer::RecvParse) MSG: MatchPacketHandler() iFd:%d", pMsg->iFd);
}
}
} else {
if (iLen == 0) {
//maybe (errno == EWOULDBLOCK || errno == EINTR || errno == EAGAIN)
gvLog(LOG_MSG, "(TcpServer::RecvParse) (iLen == 0) iFd:%d", pMsg->iFd);
} else {
gvLog(LOG_MSG, "(TcpServer::RecvParse) mio2_close iFd:%d", pMsg->iFd);
mio2_close(m, pMsg->iFd);
}
gvLog(LOG_MSG, "(TcpServer::RecvParse) MSG: fail iFd:%d pMsg:%p", pMsg->iFd, pMsg);
PutIdleMsgBuff(pMsg);
}
gvLog(LOG_MSG, "(TcpServer::RecvParse) left receive parser... pMsg:%p", pMsg);
}
usleep(1);
}
}
开发者ID:KingsleyYau,项目名称:PushServer,代码行数:59,代码来源:TcpServer.cpp
示例8: main
int main(void)
{
TcpServer ts;
ts.start();
return 0;
}
开发者ID:Comp445,项目名称:FTPWinSock_Client_Server_App,代码行数:8,代码来源:server.cpp
示例9: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TcpServer w;
w.show();
return a.exec();
}
开发者ID:Pengfei-Gao,项目名称:develop-reference-data,代码行数:8,代码来源:main.cpp
示例10: accept
void TcpSocketImpl::accept(TcpServer& server, const TcpSocketOptions& o)
{
int fd = server.impl().accept(o);
bool inherit = false;
System::IODeviceImpl::open(fd, inherit);
log_debug( "accepted " << server.impl().fd() << " => " << this->fd() );
}
开发者ID:3Nigma,项目名称:frayon,代码行数:9,代码来源:TcpSocketImpl.cpp
示例11: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TcpServer *server = new TcpServer(2);
server->startServer();
return a.exec();
}
开发者ID:aleandr100,项目名称:Snake,代码行数:10,代码来源:main.cpp
示例12: OnCloseClient
void TcpServer::OnCloseClient( uv_handle_t* handle ) {
Client& client = *( static_cast<Client*>( handle->data ) );
TcpServer* socket = client.p_server;
client.b_connected = false;
socket->DisposeClient( client.id );
if ( socket->m_close_client_callback ) {
socket->m_close_client_callback( client.id );
}
}
开发者ID:jacres,项目名称:logger,代码行数:11,代码来源:tcpServer.cpp
示例13: main
int main(void)
{
TcpServer *server = new TcpServer();
server->Start();
free(server);
return 0;
}
开发者ID:xxg1413,项目名称:NetworkProgramming,代码行数:11,代码来源:main.cpp
示例14: initRtspServer
API_EXPORT int API_CALL initRtspServer(unsigned short port) {
s_pRtspSrv.reset(new TcpServer<RtspSession>());
try {
s_pRtspSrv->start(port);
return 0;
} catch (std::exception &ex) {
s_pRtspSrv.reset();
WarnL << ex.what();
return -1;
}
}
开发者ID:owenpanqiufeng,项目名称:ZLMediaKit,代码行数:11,代码来源:common.cpp
示例15: main
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QTranslator translator(0);
translator.load("tcpserver_zh",".");
a.installTranslator(&translator);
TcpServer *tcpserver = new TcpServer();
tcpserver->show();
return a.exec();
}
开发者ID:gonboy,项目名称:Ubuntu-chatroom,代码行数:12,代码来源:main.cpp
示例16: if
void TcpServer::_listen_cb( int fd, short events, void * arg )
{
if(events & EV_READ)
{
TcpServer * server = (TcpServer *)arg;
server->Accept();
}
else if(events & EV_WRITE)
{
TcpServer * server = (TcpServer *)arg;
event_base_loopbreak(server->_base);
}
}
开发者ID:KimimaroTsukimiya,项目名称:w3hostbot,代码行数:13,代码来源:TcpServer.cpp
示例17: assert
void TcpServer::OnNewConnection( uv_stream_t* server_stream, int status ) {
assert( status == 0 );
TcpServer* server = static_cast<TcpServer*>( server_stream->data );
if ( status == -1 ) {
} else {
int client_id = server->Accept();
if ( client_id && server->m_new_client_callback ) {
server->m_new_client_callback( client_id );
}
}
}
开发者ID:jacres,项目名称:logger,代码行数:13,代码来源:tcpServer.cpp
示例18: uv_close
void TcpServer::OnRead( uv_stream_t* stream, ssize_t num_read, const uv_buf_t* buf ) {
Client* client = static_cast<Client*>( stream->data );
TcpServer* server = client->p_server;
if ( num_read < 0 ) {
uv_close( reinterpret_cast<uv_handle_t*>( stream ), TcpServer::OnCloseClient );
delete buf->base;
return;
}
if ( server->m_read_callback ) {
server->m_read_callback( client->id, buf->base, num_read );
}
delete buf->base;
}
开发者ID:jacres,项目名称:logger,代码行数:16,代码来源:tcpServer.cpp
示例19: onClientDisconnected
void onClientDisconnected(FramedTcpConnection *con,
FramedTcpConnection::DisconnectReason reason)
{
cout << "Client " << con->remoteHost().toString() << ":"
<< con->remotePort() << " disconnected,"
<< server->numberOfClients() << " clients connected\n";
/* Don't delete the con object, the TcpServer will do it */
}
开发者ID:dl1esk,项目名称:svxlink,代码行数:8,代码来源:AsyncFramedTcpServer_demo.cpp
示例20: staticAccept
err_t TcpServer::staticAccept(void *arg, tcp_pcb *new_tcp, err_t err)
{
TcpServer* con = (TcpServer*)arg;
if (con == NULL)
{
debugf("NO CONNECTION ON TCP");
//closeTcpConnection(new_tcp);
tcp_abort(new_tcp);
return ERR_ABRT;
}
else
con->sleep = 0;
err_t res = con->onAccept(new_tcp, err);
return res;
}
开发者ID:Hukuma23,项目名称:WS,代码行数:17,代码来源:TcpServer.cpp
注:本文中的TcpServer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论