本文整理汇总了C++中ServerSocket::RecvData方法的典型用法代码示例。如果您正苦于以下问题:C++ ServerSocket::RecvData方法的具体用法?C++ ServerSocket::RecvData怎么用?C++ ServerSocket::RecvData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServerSocket
的用法示例。
在下文中一共展示了ServerSocket::RecvData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char * argv[])
{
//Variables initialization:
int port = 54321;
string ipAddress;
string id = "user";
bool done = false;
char recMessage[STRLEN];
//Server
ServerSocket sockServer;
cout<<"Server started..."<<endl;
sockServer.StartHosting( port );
while ( true )
{
//Protocol to initiate communication with the client:
cout << "Prompting for login..." <<endl;
sockServer.SendData(stringToCharArray("LOGIN"));
sockServer.RecvData( recMessage, STRLEN );
if(checkName(recMessage, id) == false){
cerr << "Invalid User ID: '" << recMessage <<"'" << endl;
sockServer.SendData(stringToCharArray("UNWELCOME"));
sockServer.CloseConnection();
sockServer.Listen();
}else{
cout << "User '"<< recMessage << "' logged in successfully." << endl;
sockServer.SendData(stringToCharArray("WELCOME"));
while(!done){
sockServer.RecvData( recMessage, STRLEN );
cout<<"Received: > "<<recMessage<<endl;
if ( strcmp( recMessage, "QUIT")==0 ){
sockServer.CloseConnection();
sockServer.Listen();
//cout << "Connection closed. Exiting the program" << endl;
//return 0;
//done = true;
}else{
checkCommand(recMessage, sockServer);
}
}
}
}
return 0;
}
示例2: main
int main(){
int port = 8888;
string ipAddress;
bool done;
char recMessage[STRLEN];
char sendMessage[STRLEN];
ServerSocket sockServer;
cout<<"HOSTING..."<<endl;
sockServer.StartHosting( port );
//Connected
while ( !done )
{
cout<<"\t--WAIT--"<<endl;
sockServer.RecvData( recMessage, STRLEN );
cout<<"Recv > "<<recMessage<<endl;
sockServer.GetAndSendMessage();
if ( strcmp( recMessage, "end" ) == 0 || strcmp( sendMessage, "end" ) == 0 ){
done = true;
}
}
}
示例3: menuDisplay
void menuDisplay() {
if (!done) {
if ( choice == 2 )
{
sockClient.SendData(player1->getName());
cout<<"\t--WAIT--"<<endl;
sockClient.RecvData( recMessage, STRLEN );
cout<<"Recv > "<<recMessage<<endl;
player1->setName(name);
player2->setName(recMessage);
done = true;
recvd = true;
}
else if ( choice == 1 )
{
cout<<"\t--WAIT--"<<endl;
sockServer.RecvData( recMessage, STRLEN );
player1->setName(recMessage);
player2->setName(name);
cout<<"Recv > "<<recMessage<<endl;
sockServer.SendData(player2->getName());
done = true;
recvd = false;
}
}
glMatrixMode( GL_MODELVIEW ); // Setup model transformations
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
drawGLString(-0.5 , 0.5, 1, "Welcome to MiniGolf!");
drawGLString(-0.5 , 0.0, 1, "Press 'b' to Begin");
drawGLString(-0.5, -0.5, 1, "Press 'h' to display High Scores");
glPopMatrix();
}
示例4: display_obj
//.........这里部分代码省略.........
glPopMatrix();
glPushMatrix();
glTranslatef(ball->getPos()[0],ball->getPos()[1],ball->getPos()[2]);
glColor3f(1,1,1);
glutSolidSphere(BALL_RADIUS,20,16);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glColor3f(1,1,0);
glBegin(GL_LINES);
glVertex3d(0,0,0);
glVertex3d(ball_speed*10*ball->getDirection()[0],0,ball_speed*10*ball->getDirection()[2]);
glEnd();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glPopMatrix();
glPushMatrix();
glTranslatef(ball2->getPos()[0],ball2->getPos()[1],ball2->getPos()[2]);
glColor3f(1,0,0);
glutSolidSphere(BALL_RADIUS,20,16);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glColor3f(1,1,0);
glBegin(GL_LINES);
glVertex3d(0,0,0);
glVertex3d(ball_speed*10*ball2->getDirection()[0],0,ball_speed*10*ball2->getDirection()[2]);
glEnd();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glPopMatrix();
ball->Update();
ball2->Update();
if (!posgive) {
if ( choice == 2 )
{
//sockClient.SendData(itoa(ball_speed*1000, buffer,10));
sockClient.SendData(itoa(direction_theta*1000, buffer,10));
}
else if ( choice == 1 )
{
//sockServer.SendData(itoa(ball_speed*1000, buffer, 10));
sockServer.SendData(itoa(direction_theta*1000, buffer,10));
}
posgive = true;
}
if (!recvd) {
if ( choice == 2 && player2->getTurn())
{
sockClient.RecvData(recPos, STRLEN);
float dir = atoi(recPos)/1000.;
ball2->setDirection(cos(dir),0,sin(dir));
ball2->setSpeed(0.05);
ball2->setFriction(-0.0005);
player2->incrementCurrentScore();
recvd = true;
shot = true;
}
else if ( choice == 1 && player1->getTurn())
{
sockServer.RecvData(recPos, STRLEN);
float dir = atoi(recPos)/1000.;
ball->setDirection(cos(dir),0,sin(dir));
ball->setSpeed(0.05);
ball->setFriction(-0.0005);
player1->incrementCurrentScore();
recvd = true;
shot = true;
}
}
if (shot) {
if ((ball->getSpeed() == 0 && player1->getTurn()) || (ball2->getSpeed() == 0 && player2->getTurn())) {
player1->switchTurn();
player2->switchTurn();
shot = false;
recvd = false;
}
}
win = Physics::checkCollisions(ball, tiles, hole);
win = Physics::checkCollisions(ball2,tiles,hole);
if (win) {
//Add score to high score if it beats current score
L->setScore(L->currLevel , player1->getCurrentScore(), player1->getName());
//L->displayScores();
L->writeScores();
tiles.clear();
L->currLevel++;
//level_counter++;
if (L->currLevel==NUM_LEVELS)
L->currLevel = 0;
init();
tiles = FileReader::parseLevelFile(levels[L->currLevel], tiles, ball, ball2, tee, hole);
}
}
glFlush(); // Flush OpenGL queue
glutSwapBuffers(); // Display back buffer
}