本文整理汇总了C++中Network::Send方法的典型用法代码示例。如果您正苦于以下问题:C++ Network::Send方法的具体用法?C++ Network::Send怎么用?C++ Network::Send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Network
的用法示例。
在下文中一共展示了Network::Send方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleBackupStart
static int HandleBackupStart(Network &net, ChunkDB &chunk_db)
{
printf("backup start\n");
strcpy(backup_path, recv_buf+1);
int ret = 1;
send_buf[0] = BACKUP_START_REP;
send_buf[1] = 1;
files_info_fp = fopen(kFilesInfoPath, "w");
if(files_info_fp == NULL)
{
send_buf[1] = -1;
ret = -1;
}
files_compose_fp = fopen(kFilesComposePath, "wb");
if(files_compose_fp == NULL)
{
send_buf[1] = -2;
ret = -2;
}
current_file_compose_offset = 0;
if(chunk_db.OpenDB() < 0)
{
send_buf[1] = -3;
ret = -3;
}
if(InitContainerRecord() < 0)
{
send_buf[1] = -4;
ret = -4;
}
char tmp_path[kMaxPathLen];
GetContainerPath(current_container_id, tmp_path);
write_container_fd = fopen(tmp_path, "a");
if(write_container_fd == NULL)
{
send_buf[1] = -5;
ret = -5;
}
if(net.Send(send_buf, 2) < 0)
{
ret = -6;
}
total_chunk_count = 0;
same_chunk_count = 0;
total_chunk_bytes = 0;
save_chunk_bytes = 0;
return ret;
}
示例2: HandleIncData
static int HandleIncData(Network &net)
{
fwrite(recv_buf+1, 1, msg_len-1, current_inc_fd);
send_buf[0] = INC_DATA_REP;
if(net.Send(send_buf, 1) < 0)
return -1;
return 1;
}
示例3: HandleIncStart
static int HandleIncStart(Network &net)
{
send_buf[0] = INC_START_REP;
current_inc_fd = fopen(kCurrentIncFilePath, "wb");
if(current_inc_fd == NULL)
send_buf[1] = 0;
else
send_buf[1] = 1;
if(net.Send(send_buf, 2) < 0)
return -1;
return 1;
}
示例4: HandleChunkStart
static int HandleChunkStart(Network &net)
{
memcpy(¤t_chunk_count, recv_buf+1, 4);
strcpy(current_file_path, recv_buf+5);
total_chunk_count += current_chunk_count;
file_chunks.clear();
send_buf[0] = CHUNK_START_REP;
if(net.Send(send_buf, 1) < 0)
return -1;
return 1;
}
示例5: main
int __cdecl main(void)
{
// Create a SOCKET for connecting to server
// Setup the TCP listening socket
Network nt;
int iResult;
SOCKET ListenSocket;
ListenSocket = nt.Bind("0.0.0.0", "5005");
ListenSocket = nt.Listen(ListenSocket);
SOCKET ClientSocket = nt.Accept(ListenSocket);
char recvbuf[DEFAULT_BUFLEN];
// Receive until the peer shuts down the connection
do {
nt.Recv(ClientSocket, recvbuf);
// Echo the buffer back to the sender
nt.Send(ClientSocket, "hello my name");
} while (ClientSocket != INVALID_SOCKET);
// shutdown the connection since we're done
iResult = shutdown(ClientSocket, SD_SEND);
if (iResult == SOCKET_ERROR) {
printf("shutdown failed with error: %d\n", WSAGetLastError());
closesocket(ClientSocket);
WSACleanup();
return 1;
}
// cleanup
closesocket(ClientSocket);
WSACleanup();
return 0;
}
示例6: HandleChunkEnd
static int HandleChunkEnd(Network &net)
{
send_buf[0] = CHUNK_END_REP;
for(Uint4 i = 0; i < current_chunk_count; i++)
{
if(file_chunks[i].is_duplication)
{
send_buf[1+i] = 1;
}
else
{
send_buf[1+i] = 0;
}
}
if(net.Send(send_buf, current_chunk_count+1) < 0)
return -1;
return 1;
}
示例7: HandleBackupEnd
static int HandleBackupEnd(Network &net, ChunkDB &chunk_db)
{
fclose(files_info_fp);
fclose(files_compose_fp);
chunk_db.CloseDB();
UpdateContainerRecord();
fclose(write_container_fd);
send_buf[0] = BACKUP_END_REP;
if(net.Send(send_buf, 1) < 0)
return -1;
printf("backup end\n");
printf("same: %u total: %u\n", same_chunk_count, total_chunk_count);
printf("save: %u total: %u\n\n\n", save_chunk_bytes, total_chunk_bytes);
return 1;
}
示例8: WinMain
//.........这里部分代码省略.........
scenenode2->attachObject(ent2);
scenenode2->setScale(Ogre::Vector3(400,0,100));
// most examples get the viewport size to calculate this; for now, we'll just
// set it to 4:3 the easy way
camera->setAspectRatio((Ogre::Real)1.333333);
camera->setPosition(Ogre::Vector3(40,100,10));
guiCamera->setPosition(0, 0, 300);
guiCamera->lookAt(node->getPosition());
// this next bit is for the sake of the input handler
unsigned long hWnd;
window->getCustomAttribute("WINDOW", &hWnd);
// set up the input handlers
Simulation *sim = new Simulation();
InputHandler *handler = new InputHandler(sim, hWnd, camera);
DataManager *dataManager = new DataManager();
GameAI* gameAI = new GameAI(dataManager);
//Create Network
Network * net = new Network(dataManager);
//net->start();
sim->requestStateChange(GUI);
gui = new GuiManager();
// networkshit
while(!net->isConnected())
{
Sleep(1000);
}
net->Send(GETGROUPS, "", "", NULL);
net->Send(LOGIN, "gast", "gast", 1);
gui->setSimulation(sim);
gui->init("", ogre, guiSceneMgr, window);
gui->activate("main");
handler->setWindowExtents(1024,768);
SimulationState cState;
Ogre::WindowEventUtilities::addWindowEventListener(window, handler);
DWORD tFrameStart = 0x0; //in miliseconds
signed long tFrameX = 0x0;
float tDelta2 = 0.0f; //in seconds
float m_fps = 60.0f;
tFrameStart = GetTickCount();
float tDelta;
//testAI->calculateNextPath(40,10);
while ((cState = sim->getCurrentState()) != SHUTDOWN) {
tFrameX = GetTickCount() - tFrameStart;
tDelta2 = (float)tFrameX / 1000.0f;
if (tDelta2 > 3600) // tDelta > 1 hour
tDelta2 = 1.0f / m_fps; //< System tick count has highly likely overflowed, so get approximation
tFrameStart = GetTickCount();
m_fps = (int)(1.0f / tDelta2);
tDelta = tDelta2;
handler->capture();
示例9: HandleIncEnd
static int HandleIncEnd(Network &net)
{
fclose(current_inc_fd);
int ret = 0;
send_buf[0] = INC_END_REP;
send_buf[1] = 1;
FILE *fp = fopen(kCurrentIncFilePath, "rb");
if(fp == NULL)
{
send_buf[1] = 0;
ret = -1;
goto clear;
}
fprintf(files_info_fp, "%s %u %u\n", current_file_path, current_file_compose_offset, current_chunk_count);
current_file_compose_offset += current_chunk_count * 10;
#ifdef DEBUG_
printf("count: %d\n", current_chunk_count);
#endif
for(Uint4 i = 0; i < current_chunk_count; i++)
{
fwrite(&file_chunks[i].container_id, 1, 4, files_compose_fp);
fwrite(&file_chunks[i].container_offset, 1, 4, files_compose_fp);
fwrite(&file_chunks[i].len, 1, 2, files_compose_fp);
if(!file_chunks[i].is_duplication)
{
#ifdef DEBUG_
printf("%d ", file_chunks[i].len);
#endif
if(kContainerCapacity - write_container_offset >= file_chunks[i].len)
{
write_container_offset += file_chunks[i].len;
}
else
{
fclose(write_container_fd);
write_container_id++;
write_container_offset = 0;
char tmp_path[kMaxPathLen];
GetContainerPath(write_container_id, tmp_path);
write_container_fd = fopen(tmp_path, "a");
if(write_container_fd == NULL)
{
send_buf[1] = 0;
ret = -2;
goto clear;
}
write_container_offset += file_chunks[i].len;
}
fread(file_buf, 1, file_chunks[i].len, fp);
fwrite(file_buf, 1, file_chunks[i].len, write_container_fd);
}
}
send_buf[1] = 1;
fclose(fp);
#ifdef DEBUG_
printf("\n");
#endif
clear:
if(net.Send(send_buf, 2) < 0)
{
ret = -3;
}
return ret;
}
示例10: HandleChunkInfo
static int HandleChunkInfo(Network &net, ChunkDB &chunk_db)
{
ChunkInfo chunk;
memcpy(&chunk.len, recv_buf+1, 2);
string key, value;
key.assign(recv_buf+3, 20);
//PrintKey(key);
total_chunk_bytes += chunk.len;
if(chunk_db.Get(key, &value) > 0)
{
chunk.is_duplication = true;
sscanf(value.c_str(), "%u,%u", &chunk.container_id, &chunk.container_offset);
file_chunks.push_back(chunk);
same_chunk_count++;
save_chunk_bytes += chunk.len;
}
else
{
chunk.is_duplication = false;
if(kContainerCapacity - current_container_offset >= chunk.len)
{
chunk.container_id = current_container_id;
chunk.container_offset = current_container_offset;
current_container_offset += chunk.len;
}
else
{
//fclose(write_container_fd);
current_container_id++;
current_container_offset = 0;
//char tmp_path[kMaxPathLen];
//GetContainerPath(current_container_id, tmp_path);
//write_container_fd = fopen(tmp_path, "a");
//if(write_container_fd == NULL)
//return -1;
chunk.container_id = current_container_id;
chunk.container_offset = current_container_offset;
current_container_offset += chunk.len;
}
char tmp[128];
sprintf(tmp, "%u,%u", chunk.container_id, chunk.container_offset);
value.assign(tmp);
if(chunk_db.Put(key, value) < 0)
return -2;
file_chunks.push_back(chunk);
}
send_buf[0] = CHUNK_INFO_REP;
if(net.Send(send_buf, 1) < 0)
{
return -3;
}
return 1;
}