Personally want to be a linux IP phone, find some SIP information, found that this agreement is large enough, watching the OSIP project for more than a year, I also think is too difficult, but I think about the difficulty, I have a challenge, self Comfort, huh, huh. The first step I want to be familiar with the process communication under Linux, I hope that there is Socket, Pipe, Queue, SigAction, etc. must be grasped first. Do not do the server, with two customer program USER Agent communication, divided into several Module: 1. Socket Processing Module 2. Signaling Resolution Module 3. Command Processing 4.UI 5. Maintenance Module 6. The Queue Communication between other modules 1 and 2. Socket is based on UDP. Two UDP communications Customer and Server: Server: BigDogsrv.c ******************************************************* ******** # include
main () {int sockfd; struct sockaddr_in my_addr; / * my address information * / struct sockaddr_in their_addr; / * connector's address information * / int addr_len, numbytes; char buf [MAXBUFLEN]; // memset (buf, "", MAXBUFLEN -1); if ((SOCKFD = Socket (AF_INET, SOCK_DGRAM, 0) == -1) {Perror ("socket"); exit (1);} my_addr.sin_family = AF_INET; / * HOST BYTE ORDER * / MY_ADDR.SIN_PORT = HTONS (MyPort); / * short, network byte order * / my_addr.sin_addr.s_addr = incdr_Addr; / * auto-fill with my ip * / bzero (& (MY_ADDR.SIN_ZERO), 8); / * Zero the rest of the struct * / if (bind (STRUCKD, STRUCKADDR *) & my_addr, sizeof (struct sockaddr)) / == -1) {PERROR ("bind"); exit (1);} addr_len = sizeof (Struct SockAddr); while (buf, "bye", 3)! = 0) {// End IF ((NumBytes = Recvfrom (sockfd, buf, maxbufflen, 0, / (struct socketdr *) & THEIR_ADDR, & Addr_Len) == -1) {Perror ("Recvfrom"); exit (1);} Printf ("Got Packet FROM% S / N", INET_NTOA (THEI R_addr. sin_addr); Printf ("Packet IS% D Bytes Long / N", NumBytes); BUF [NumBytes] = '/ 0'; Printf ("Packet Contains /"% S / "/ N", BUF); } close (sockfd);} ******************************* Client: bigdogclient.c ***** ************************* # incrude int main (int argc, char * argv []) {int sockfd; struct sockaddr_in their_addr; / * connector's address information * / struct hostent * he; int numbytes; if (argc = 3!) {fprintf (stderr, "usage: Talker hostname message / n "); exit (1);} if ((he = gethostByname) == NULL) {/ * get the host info * / human (" gethostbyname "); exit (1 }}} = ((SOCKFD = Socket (AF_INET, SOCK_DGRAM, 0) == -1) {Perror ("socket"); exit (1);} their_addr.sin_family = AF_INET; / * HOST BYTE ORDER * / THEIR_ADDR .sin_port = htons (myport); / * short, network byte order * / their_addr.sin_addr = * ((struct in_addr *) HE-> h_addr); Bzero (& (THEIR_ADDR.SIN_ZERO, 8); / * ZERO THE REST of the struct * / if ((NumBytes = sendto (Sockfd, Argv [2], Strlen (Argv [2]), 0, / (Struct SockAddr *) & their_addr, sizeof (struct sockaddr)) == -1) {Perror ("Sendto"); exit (1);} Printf ("SENT% D Bytes TO% S / N", NumBytes, INET_NTOA (THEIR_ADDR.SIN_ADDR); Close (SockFD); Return 0;} *** ***************** **************** Makefile: Simple written ********************************** CC = GCC SRV: BigDogsrv.o $ (cc) -o srv bigdogsrv.obigdogsrv.o: Bigdogsrv.c $ (cc) -c -g bigdogsrv.c Client: BigDogClient.O $ (cc) -o Client BigdogClient.obigdogClient.o: BigdogClient.c $ (cc) -c -g bigdogclient.c Clean: rm -f * .o RM -F SRV RM -F Client ****************************************** **** Makemake Client then run SRV first, Run the Client 192.168.1.168 Love you