![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 | |
|
Professional Programmer
|
Winsock: specified sending
I'm having trouble finding the error here. When I have multiple users connected to the server, if one user sends a message, the server will end up sending it back to all users(including the user who sent the original message). What I need to do is allow the server to send to all users minus the original sender. Here's what my code looks like, the commented area is where I'm assuming the code needs some fixing, but I've tried a bunch of different combinations of removing the original sender from the sending sockets, but then the server only sends to certain users.
if ((bytes = recv(i, recvbuf, sizeof(recvbuf), 0)) <= 0)
{
for(int h = 0; h < my_vec.size(); h++)
{
tempuser.id = i;
tempuser2 = my_vec.at(h);
if(tempuser2.id == tempuser.id)
{
my_vec.erase(my_vec.begin()+h);
}
}
std::cout << tempuser2.name << " has left the server. Socket "
<< i << " is now free." << std::endl;
closesocket(i);
FD_CLR(i, &master);
} else {
for(j = 0; j <= fdmax; j++)
{
if (FD_ISSET(j, &master))
{
{
if(j == i)break; // if the sending socket is equal to the socket receiving the message, exit loop.
send(j, recvbuf, sizeof(recvbuf), 0);
}
}
}
}
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sending INT over winsock | Aourhgad | C++ | 6 | Jul 25th, 2006 10:30 PM |
| Winsock HTTP File Transfer | kruptof | Visual Basic | 1 | Jun 19th, 2006 4:47 AM |
| Sending files via winsock | dmitry_k53 | Visual Basic | 5 | May 20th, 2006 4:18 PM |
| Winsock Create//Connect Problem. | HackeZ | C++ | 6 | Dec 3rd, 2005 5:26 PM |
| sending .zip files with winsock | Brent | C++ | 6 | Aug 29th, 2005 5:55 PM |