Jump to content
  • Advertisement

TheRaider Tut

Member
  • Content Count

    8
  • Joined

  • Last visited

Community Reputation

0 Neutral

About TheRaider Tut

  • Rank
    Newbie

Personal Information

  • Role
    Programmer
  • Interests
    Education
    Programming
  1. TheRaider Tut

    Retrieving the list of clients from the c ++ socket

    When the player disconnects, his thread is closed via join(); I discovered that first and second client each other change their variables which, they use the same variables, How i can fix it?
  2. TheRaider Tut

    Retrieving the list of clients from the c ++ socket

    I have a server, after accept it is being created thread for a client, and i have problem here, when second client connects are happening strange things, packets which are send via server they are distorted, same with receiving, earlier i getting clear packets, and after connecting second client receiving packets they began to have strange characters. Code: ..sock etc. //bind if(bind(server, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { perror("Fail bind"); exit(1); } std::cout << "=> Looking for clients..." << std::endl << std::endl; std::vector <int> connection; int clients = 0; while( rc >= 0 ) { rc = listen( server, 50); if( rc < 0) { perror("listen"); close( server ); } else { size = sizeof(client_addr); client = accept( server, ( struct sockaddr * ) & client_addr, & size ); connection.push_back( client ); std::thread th(show, connection, clients); threads.push_back(std::move(th)); clients++; } } show(); - is a function that supports the game client, receives and sends packets all the time, works until the client disconnects. Any idea how i can fix it?
  3. TheRaider Tut

    Retrieving the list of clients from the c ++ socket

    There is no simpler way to do this without state machines?
  4. TheRaider Tut

    Retrieving the list of clients from the c ++ socket

    Would you give any advice, or send a guide on how to create such a state machine? If the threads are bad, I will choose something else.
  5. TheRaider Tut

    Retrieving the list of clients from the c ++ socket

    hClient is my class, and the Thread is a function of the hClient class, this function does all my game. This feature receives and sends packets, all the time is enabled until the client leaves the game
  6. TheRaider Tut

    Retrieving the list of clients from the c ++ socket

    @hplus0603 I think I'm doing it wrong, can you help me? I made this code, but the accept still blocks the loops of my game for new clients: if( listen( server, 50) < 0) { perror("listen"); exit(1); } fd_set read_fds; int fdmax = server; while(1) { FD_ZERO( &read_fds ); FD_SET( server, &read_fds); select( fdmax + 1, & read_fds, NULL, NULL, NULL); for(int i = 0; i < fdmax; i++) { if(FD_ISSET( server, & read_fds ) ) { size = sizeof( client_addr ); if( ( client = accept( server, ( struct sockaddr * ) & client_addr, & size ) ) < 0 ) { perror("accept"); } if (client > fdmax ) fdmax = client; connection.push_back(client); hClient.Thread(); clients++; } } }
  7. I have a question about downloading the list of connected clients of the c++ sockets, how to send the first connected client information about the other one who connected right after it? the first client connects, writes the socket to std::vector <int> connection using connection.push_back (socket) starts a thread, then it increases by one int clients. When the second client connects, puts socket into the vector, runs the thread, increases clients++ and has all the information about the first client, and the client first has no information about the second client, the vector connection does not change, nor does the clients increase. The second client can send the message to himself and the client first using the for loop (int i = 0; i <clients + 1; i ++) send ("message"), but the client can only do the same for himself, how to deal with it? global variables: std::vector <int> connection; int clients; code: size = sizeof(client_addr); client = accept( server, ( struct sockaddr * ) & client_addr, & size ); connection.push_back(client); //thread if(!fork()) { Client hClient; hClient.Thread(); } //thread clients++;
  8. Hello, i have a few question about socket in c++! First question, let's say that he writes a server for the game in which he will play 200 people at once, but accept is blocked because he already serves one client, how to deal with it? Second question, how to download a list of all currently connected clients, so that you can then send a package to everyone?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!