本文整理汇总了C++中Connection::Send方法的典型用法代码示例。如果您正苦于以下问题:C++ Connection::Send方法的具体用法?C++ Connection::Send怎么用?C++ Connection::Send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::Send方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Send
void Send( GamePadEvent event, MSGINDEX index = 0 )
{
const bool sendingFirstTime = index == 0;
event.id = sendingFirstTime ? m_msgIndex++ : index;
if( !LosePacket() ) // simulate packets loss
m_UDPtoServer.Send( reinterpret_cast< char* >( &event ), sizeof( event ) );
if( sendingFirstTime /*need to re-send after a short wait*/ )
WaitAndSendAsync( event );
}
示例2: Execute
void Service::Execute(const std::string& host, int port, Command& cmd)
{
cmd.status() = Command::EXECUTING;
Connection *con = new TCPConnection(host, port);
if (!con->Open())
{
delete con;
throw "Could not connect to " + host;
}
con->Send(&cmd.Msg());
Message *rsp = con->Recv();
cmd.ReadMessage(*rsp);
delete rsp;
}
示例3: ConnectToAllEntities
/*!
* \brief Connects and synchronize every entity, as specified in cpw::Remote
* \param entity The root entity from which start connecting. Default value (NULL) makes it use the Top Layer
*
* Connects and synchronize every entity, as specified in cpw::Remote.
*/
void RemoteProtocol::ConnectToAllEntities(cpw::Entity *entity)
{
if (entity == NULL)
entity = layer_tree->GetTopLayer();
if (entity != NULL)
{
std::vector<cpw::RemoteNode> nodes = ((cpw::Remote*) entity)->GetNodes();
std::vector<cpw::RemoteNode>::iterator it;
for (it = nodes.begin(); it != nodes.end(); it++)
{
cpw::RemoteNode n(it->GetIPAddress(), 3000);
Connection *connection = connection_manager->Connect(n);
if (connection != NULL)
{
GetEntityRequestData *message = new GetEntityRequestData();
message->SetEntityId(entity->GetId());
message->SetSendEntity(false);
connection->Send(message);
if ( message )
{
delete message;
message = NULL;
}
}
}
if (entity->isContainer())
{
//create children
for (int i=0; i<entity->GetNumChildren(); i++)
{
cpw::Entity *child=entity->GetChild(i);
ConnectToAllEntities(child);
}
}
}
}
示例4: main
int main(int argc, char** argv)
{
if (!Initialize())
{
cout << "Failed to initialize socket layer\n";
system("pause");
return -1;
}
if (!Bind(PORT))
{
cout << "Failed to bind listening socket\n";
system("pause");
Cleanup();
return -1;
}
Connection SendingSocket;
char choice;
char IP[16];
cout << "Host or Join (h/j)\n";
cin >> choice;
if (choice == 'h')
{
if (!ReceivingSocket.Accept())
{
cout << "Error while connecting to partner\n";
system("pause");
Cleanup();
return -1;
}
if(!SendingSocket.Accept())
{
cout << "Error while connecting to partner\n";
system("pause");
Cleanup();
return -1;
}
}
else
{
cout << "IP: ";
cin >> IP;
if (!SendingSocket.Connect(IP, PORT))
{
cout << "Error while connecting to partner\n";
cout << StringError() << endl;
system("pause");
Cleanup();
return -1;
}
if(!ReceivingSocket.Connect(IP, PORT))
{
cout << "Error while connecting to partner\n";
cout << StringError() << endl;
system("pause");
Cleanup();
return -1;
}
}
HRESULT result;
IAudioCaptureClient* capture_client = NULL;
IAudioClient* audio_client_capture = NULL;
IMMDevice* capture_device = NULL;
IMMDeviceEnumerator* enumerator = NULL;
IPropertyStore* propstore_capture = NULL;
PROPVARIANT pv_capture;
WAVEFORMATEX* wf_capture = NULL;
UINT32 packSize;
UINT32 availableFrames;
UINT32 timeIntervalForBuffer = 1000000;
UINT32 timeIntervalInMilliseconds = timeIntervalForBuffer / 10000;
BYTE* pData = NULL;
DWORD flags;
float index = 0;
result = CoInitialize(0);
if (FAILED(result))
{
printf("Failed to initialize\n");
goto Exit;
}
result = CoCreateInstance(
__uuidof(MMDeviceEnumerator), NULL,
CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
(void**)&enumerator);
if (FAILED(result))
{
printf("Failed to create device enumerator\n");
goto Exit;
}
result = enumerator->GetDefaultAudioEndpoint(eCapture, eCommunications, &capture_device);
if (FAILED(result))
{
printf("Failed to get capture endpoint handle\n");
goto Exit;
}
PropVariantInit(&pv_capture);
result = capture_device->OpenPropertyStore(STGM_READ, &propstore_capture);
if (FAILED(result))
//.........这里部分代码省略.........
示例5: memset
void * http_event_loop(void *arg){
int event_thread_id = (*(int *)arg);
int sock;
ssize_t read_size;
int request_counter=0;
int event_num;
int max_events = 10;
int i;
int ret;
EpollManager *epoll_mng;
Connection *conn = NULL;
struct epoll_event events[max_events];
for(i=0; i<max_events; i++){
memset(&events[i], 0, sizeof(events[i]));
}
epoll_mng = server->getEpoll(event_thread_id);
if(epoll_mng == NULL){
printf("Error: getEpoll returned -1\n");
exit(-1);
}
while(1){
event_num = epoll_wait(epoll_mng->epoll, events, max_events, EPOLL_WAIT_TIMEOUT_MSEC);
if(event_num == -1){ perror("epoll_wait"); break; }
if(IsStop()){ break; }
//printf("##### epoll wait : event num = %d\n", event_num);
for(i=0; i<event_num; i++){
conn = (Connection *)events[i].data.ptr;
if(conn == NULL){
printf("Error: epoll event do not have connection\n");
exit(-1);
}
sock = conn->sock;
if(events[i].events & EPOLLIN){
// Read
ret = conn->Read();
if(ret <= 0 ){ epoll_mng->CloseConnection(conn); delete conn; conn = NULL; continue; }
// Process
ret = conn->Process();
if(ret <= 0 ){ epoll_mng->CloseConnection(conn); delete conn; conn = NULL; continue; }
}
if(events[i].events & EPOLLOUT){
// Send
ret = conn->Send();
if(ret <= 0 ){ epoll_mng->CloseConnection(conn); delete conn; conn = NULL; continue; }
}
if((events[i].events & EPOLLRDHUP) ||
(events[i].events & EPOLLERR) ||
(events[i].events & EPOLLHUP) ){
epoll_mng->CloseConnection(conn); delete conn; conn = NULL;
continue;
}
}
epoll_mng->CheckAndCloseConnections();
}
pthread_exit(NULL);
}