Thread: Peer to Peer

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    2

    Peer to Peer

    Hi everyone, i have written a code which is a client/server application. It is UDP connection and the program uses the system call to communicate.. I have to change this so the code in the client is connected and communicated via peer to peer system.. is anyone willing to help, it'll much appreciated..

    Code:
    /* 
    
     * Name:	  client.c
    
     * Author	  dalgic
    
     * Date Created:  2005
    
     * Date Modified: April 2005
    
     */ 
    
    
    
    
    
    #include"user.h"
    
    #include"comm.h"
    
    #include"buff.h"
    
    
    
    #define ANY_PORT 0
    
    
    
    
    
    #define KEYBOARD 0	/* File Descriptor for Keyboard (1 = stdout, 2 = stderr) */
    
    
    
    
    
    
    
    
    
    int main(int argc, char *argv[])
    
     {
    
      int sd;
    
      Id server,fromA; 
    
      int n,rc;
    
      int process_id;
    
      char usrtxt[80];
    
      int portno;
    
    
    
    
    
    
    
    
    
      fd_set readfds, activefds;	/* Read and Active file descriptor set. */
    
      int fd, nfds;			/* (Variables for Select Arguments) */
    
    
    
      nfds = getdtablesize();
    
    
    
    
    
    
    
      
    
    
    
    
    
      if(argc<2){                     /* check command line args */
    
        printf("usage : %s <server-host> [optional: server-port] \n", argv[0]);
    
        exit(1); 
    
      }
    
    
    
      if(argc<3) portno = SERVER_PORT;
    
      else portno = atoi(argv[2]);
    
    
    
                                     /* fill in addr. rec. for remote server*/
    
      hname2Addr(&server, argv[1], portno);  /* get address of the server */
    
      sd = getSock(ANY_PORT,SOCK_DGRAM);          /* obtain any available port */
    
      n = putReg();                 /* set registration message onto out buff */
    
      rc =out_to(sd, &server, n);       /* send out the registration request */
    
    
    
    
    
    
    
    	/*	*	*	*	*	*/
    
    
    
      FD_ZERO(&activefds);
    
      FD_SET(sd, &activefds);
    
      FD_SET(KEYBOARD, &activefds);
    
    
    
      while(1)
    
      {
    
    
    
         memcpy(&readfds, &activefds, sizeof(readfds) );
    
    
    
    
    
         prompt("p:itext>>");	   /* Show User Prompt, then check for input... */
    
    
    
    
    
         if ( select(nfds, &readfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0) < 0)
    
         {
    
    	printf("Error in Select!" );	/* Error in select call */
    
         }
    
    
    
    
    
         if (FD_ISSET (KEYBOARD, &readfds) )	   /* >> Its the keybaord thats ready! */
    
         {
    
    
    
    	 getTxt(usrtxt,80);                /* get text from the user */
    
             n = putTxt(usrtxt);               /* put it onto out buffer */
    
             out_to(sd, &server,n);            /* send it to the server */ 
    
             if(strcmp(usrtxt,"quit\n")==0)    /* termination command ! */
    
    	    exit(1);
    
         }
    
    
    
    
    
         if (FD_ISSET (sd, &readfds) )		 /* >> Its the socket thats ready! */       
    
         {
    
             n = in_from(sd, &fromA);         /* handle incomming messages */
    
             if(isMsg(TAB))
    
             {
    
                 saveTab();showTab();
    
             } 				/* based on type of msg received */ 
    
             else
    
             {                            
    
                 showTxt();                  /* print text on screen */
    
                 if(isText("quit\n"))
    
                 {       /* termination command ? */
    
                    chkExit();                  /* exit if addr. matches self Id */ 
    
                    tabDel(getix());            /* del quitter  */
    
    
    
                    printf("\n One member left, %d remaining",tabLen()); 
    
                 }
    
    	 }         
    
    
    
             prompt("c:itext>>");             /* keep screen tidy !*/
    
         }
    
      }
    
    
    
    		/*	*	*	*	*	*/
    
    
    
      
    
      return 1;
    
    
    
    }

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You could start by removing extra newlines in your code.

    Are you having some kind of difficulties with the code? Project recruitments would probably be better off on the Projects board.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    2
    yeh i am having problems with the code , what im tryin to do is, make this client actually connects to a server, when a message is sent it is first sent to the server, and then the server sends it out to the clients.

    what i want to do is remove the point of the server, so when the client sends a message instead of going to the server > client, i want it to go straight to the clients..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Peer to Peer Tcp
    By stevesmithx in forum Networking/Device Communication
    Replies: 10
    Last Post: 10-06-2007, 10:04 AM
  2. peer to peer wifi communication
    By odysseus.lost in forum Networking/Device Communication
    Replies: 2
    Last Post: 07-20-2006, 04:51 AM
  3. Request for peer review
    By ruthgrin in forum C++ Programming
    Replies: 13
    Last Post: 01-26-2006, 10:03 PM
  4. OOP for DirectPlay Peer to Peer program
    By curlious in forum Networking/Device Communication
    Replies: 0
    Last Post: 11-04-2003, 12:21 AM