Please help! Network programming error :/
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Please help! Network programming error :/

  1. #1
    Join Date
    Dec 2010
    Posts
    2

    Please help! Network programming error :/

    Hello everyone..

    I have a problem.. The main idea of my project is a server that accept client connections and everytime someone connects it checks if the client is available for reading or for writing with select() function.
    If is ready for writing then is send a buffer.. Well, this is a sample of code..

    ...
    FD_ZERO(&master);
    FD_SET(fdmax, &master);
    for(; {
    read_fds = master;
    write_fds = master;

    if(select(fdmax + 1, &read_fds, &write_fds, NULL, NULL) == -1) {
    perror("select");
    return -1;
    }


    for(i = 0; i <= fdmax; i++) { // check through all socket

    if(FD_ISSET(i, &read_fds) != 0) {

    bla bla bla

    }

    if(FD_ISSET(i, &write_fds)) { // teh client is ready for writing

    printf("send bytes: %ld\n", sizeof(jobs[counter]) );
    bytes = send(i, &jobs[counter], sizeof(jobs[counter]), 0);

    counter++;
    }


    also the client source is..

    while(f == 0) {

    memset(&jobs, 0, sizeof(jobs));




    if((bytes = recv(sockfd, &jobs, sizeof(jobs), 0)) == -1) {
    printf("Error recving\n");
    }

    printf("here");

    bla bla bla
    }

    the problem is that the server althougt is was supposed to send the msg only 1 time it is send it 10-15 times... it is like finds the client client all the time available for writing ( maybe i am doing sthng wrong with select and fds?).. Also the client exiting with segmentation fault JUST AFTER the printf function and i dunno why.. i suppose it is from the "oversending" of the packets from the server

    What should i do ? Thanks in advance..
    (i compiled it with gcc on Ubuntu distro)

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: Please help! Network programming error :/

    Quote Originally Posted by Zisis View Post
    What should i do ? Thanks in advance..
    The first thing you have to do is edit your post to add Code tags around code snippets and proper code indentations inside the snippets. Otherwise your "code" is absolutely unreadable.

    See Announcement: Before you post....
    Victor Nijegorodov

  3. #3
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,109

    Re: Please help! Network programming error :/

    you have to re-initialise your read_fds and write_fds after select() returns, because they will be altered by the select() call.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center