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



LinkBack URL
About LinkBacks



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