As we all know,most our projects are need to use the socket to programme.Use socket we can connect our device to others and our client to the Internet,so it's made our product more powerful.Now,let's begin the key part-pjlib socket.
The date types and functions are too much,if you need some of them,just click the links.
http://www.pjsip.org/docs/latest/pjlib/docs/html/page_pjlib_sock_test.htm
test1:get hostname and host address
1 //PJLIP I/O 2 //Socket test->get hostname and hostaddress 3 //heat nan 4 #include<pjlib.h> 5 int main() 6 { 7 pj_status_t status; 8 pj_in_addr hostaddr; //This structure describes Internet address. 9 // dada fields pj_uint32_t s_addr. The 32bit IP address. 10 unsigned char *hostaddr_str; 11 const pj_str_t *hostname; 12 //pj_init 13 status=pj_init(); 14 if(status!=PJ_SUCCESS) 15 { 16 PJ_LOG(3,(" ","init failed!")); 17 } 18 //gethostname 19 hostname=pj_gethostname(); 20 if(!hostname||!hostname->ptr||!hostname->slen) 21 { 22 PJ_LOG(3,( "gethostname","faild")); 23 } 24 else 25 { 26 PJ_LOG(3,("gethostname","the hostname is %s",hostname->ptr)); 27 } 28 hostaddr=pj_gethostaddr(); 29 if(hostaddr.s_addr) 30 { 31 hostaddr_str=pj_inet_ntoa(hostaddr);//function pj_in_addr -> char * 32 //Convert an Internet host address given in network byte order to string in standard numbers and dots notation. 33 PJ_LOG(3,("gethostaddress","%s",hostaddr_str)); 34 } 35 else 36 { 37 PJ_LOG(3,("gethostaddress","failed")); 38 } 39 40 pj_shutdown(); 41 getchar();//show the result before you enter any key 42 }