Programming Forums
User Name Password Register
 

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

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Dec 5th, 2007, 1: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
 

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 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




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

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