Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 5th, 2007, 2:32 PM   #1
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
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:
Originally Posted by Mohamed Jihad
Durka durka!
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!
jayme is offline   Reply With Quote
Old Dec 5th, 2007, 7:15 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 894
Rep Power: 4 The Dark is on a distinguished road
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)
  1. ...
  2. {
  3. // if the sending socket is equal to the socket receiving the message, don't send.
  4. if(j != i)
  5. send(j, recvbuf, bytes, 0);
  6. }
  7. ...
The Dark is offline   Reply With Quote
Old Dec 5th, 2007, 7:24 PM   #3
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
Re: Winsock: specified sending

Wow, how did I miss that? Eh, what's done is done.

Thanks.
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
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!
jayme is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:14 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC