socket programming in c or c++ in linux...

This is a discussion on socket programming in c or c++ in linux... within the Linux Programming forums, part of the Platform Specific Boards category; hello everyone, i have read the small basic of socket programming in c and now i want to read more ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    Question socket programming in c or c++ in linux...

    hello everyone,
    i have read the small basic of socket programming in c and now i want to read more about it in advance level where i can deal with steaming of data
    on network. is there ny tutorial available about advance socket programming in c or c++??
    i am using gcc or g++ compiler in linux os.
    and also i want to learn how to create gui in c or c++...share any gud link if nyone have...thnx
    plz help.

  2. #2
    EOP
    EOP is offline
    Registered User
    Join Date
    Jan 2008
    Posts
    45
    Beej's Guide to Network Programming
    Using Internet Sockets

    http://beej.us/guide/bgnet/

  3. #3
    Distributed Programming beyonddc's Avatar
    Join Date
    Dec 2001
    Location
    Mass
    Posts
    31
    wxwidgets and qt is pretty popular library for creating cross platform GUI in C++.
    -dc

  4. #4
    Registered User
    Join Date
    Feb 2009
    Location
    Philippines
    Posts
    3
    hello!
    I have to make a user interface for a chat program in c using NCURSES. My problem is that i have codes i've found on the net but how can i integrate it to the ncurses as my UI.

    My ui must have window, for messages, other, is for online clients and last is for the space to write msgs. Can someone help me how to make one...plzzz.

    THANKS !

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Learn ncurses BEFORE you try to combine it with another topic you are also learning (like sockets). In other words, do an ncurses tutorial, make a little ncurses program that will take input, keep the screen organized, etc. and once you are comfortable with that, do the same thing with sockets and THEN integrate them.

    This will take you a few whole days no matter what.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Feb 2009
    Location
    Philippines
    Posts
    3
    hello!
    I've started to study ncurses...but i've encounter problem such as how will i extract the list of clients that are online or just joined in the chat server.

    this is my code..
    ______________________________
    http://dejant.blogspot.com/2007/08/c...gram-in-c.html

    Code:
    while (1) {
            testfds = readfds;
            select(FD_SETSIZE, &testfds, NULL, NULL, NULL);
                        
            /* If there is activity, find which descriptor it's on using FD_ISSET */
            for (fd = 0; fd < FD_SETSIZE; fd++) {
               if (FD_ISSET(fd, &testfds)) {
                  
                  if (fd == server_sockfd) { /* Accept a new connection request */
                     client_sockfd = accept(server_sockfd, NULL, NULL);
                     /*printf("client_sockfd: %d\n",client_sockfd);*/
                    
                                    
                     if (num_clients < MAX_CLIENTS) {
                        FD_SET(client_sockfd, &readfds);
                        fd_array[num_clients]=client_sockfd;
                        /*Client ID*/
                        printf("Client %d joined\n",num_clients++);
                        fflush(stdout);
                        
                        sprintf(msg,"M%d",client_sockfd);       
                        /*write 2 byte clientID */
                        send(client_sockfd,msg,strlen(msg),0);
                     }
                     else {
                        sprintf(msg, "XSorry, too many clients.  Try again later.\n");
                        write(client_sockfd, msg, strlen(msg));
                        close(client_sockfd);
                     }
                  }
                  else if (fd == 0)  {  /* Process keyboard activity */                 
                     fgets(kb_msg, MSG_SIZE + 1, stdin);
                     //printf("%s\n",kb_msg);
                     if (strcmp(kb_msg, "quit\n")==0) {
                        sprintf(msg, "XServer is shutting down.\n");
                        for (i = 0; i < num_clients ; i++) {
                           write(fd_array[i], msg, strlen(msg));
                           close(fd_array[i]);
                        }
                        close(server_sockfd);
                        exit(0);
                     }
                     else {
                        //printf("server - send\n");
                      sprintf(msg, "Message :%s", kb_msg);
                        for (i = 0; i < num_clients ; i++)
                           write(fd_array[i], msg, strlen(msg));
                     }
                  }
                  else if(fd) {  /*Process Client specific activity*/
                     //printf("server - read\n");
                     //read data from open socket
                     result = read(fd, msg, MSG_SIZE);
                     
                     if(result==-1) perror("read()");
                     else if(result>0){
                        /*read 2 bytes client id*/
                        sprintf(kb_msg,"M%d",fd);     //2 change 1
                        msg[result]='\0';
                        
                        /*concatinate the client id with the client's message*/
                        strcat(kb_msg,msg+1);                                        
                        
                        /*print to other clients*/
                        for(i=1;i<num_clients;i++){
                           if (fd_array[i] != fd)  /*dont write msg to same client*/
                              write(fd_array[i],kb_msg,strlen(kb_msg));
                        }
                        /*print to server*/
                        printf("Print to Server:%s",kb_msg+1);
                        
                         /*Exit Client*/
                        if(msg[0] == 'X'){
                           exitClient(fd,&readfds, fd_array,&num_clients);
                        }   
                     }                                   
                  }                  
                  else {  /* A client is leaving */
                     exitClient(fd,&readfds, fd_array,&num_clients);
                  }//if
               }//if
            }//for
         }//while
    ***wHICH part of the code can i extract the list of clients except myself of course, to be displayed at the right side of SERVER and CLIENT program?
    **I tried after the read() fxn but there's no any output...
    ***Can someone help me how to display the clients list?....

    THANKS!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux raw socket programming
    By cnb in forum Networking/Device Communication
    Replies: 17
    Last Post: 11-08-2010, 07:56 AM
  2. pthread and socket porting from Linux to Windows
    By mynickmynick in forum C Programming
    Replies: 2
    Last Post: 07-18-2008, 06:57 AM
  3. socket programming in linux
    By crazeinc in forum C Programming
    Replies: 1
    Last Post: 05-27-2005, 07:40 PM
  4. Linux Network Programming (server architeture)
    By curlious in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-08-2005, 04:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21