![]() |
|
![]() |
|
|
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! ▄▄▄▄ |
|
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 894
Rep Power: 4
![]() |
Re: Winsock: specified sending
I don't think you want to exit the loop when you hit "i" - that would only send the message to the portion of the users whose socket was less than the sender.
I think something like this should work in the inner if statement: c++ Syntax (Toggle Plain Text)
|
|
|
|
|
|
#3 | |
|
Professional Programmer
|
Re: Winsock: specified sending
Wow, how did I miss that? Eh, what's done is done.
Thanks.
__________________
▄▄▄▄ 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 11:30 PM |
| Winsock HTTP File Transfer | kruptof | Visual Basic | 1 | Jun 19th, 2006 5:47 AM |
| Sending files via winsock | dmitry_k53 | Visual Basic | 5 | May 20th, 2006 5:18 PM |
| Winsock Create//Connect Problem. | HackeZ | C++ | 6 | Dec 3rd, 2005 6:26 PM |
| sending .zip files with winsock | Brent | C++ | 6 | Aug 29th, 2005 6:55 PM |