linux socketСÀý
/*
socket selectÄ£ÐÍ£¬·þÎñ¶Ë
¾ø´ó¶àÊý×¢ÊÍ×Ô¼ºÐ´µÄ£¬²Î¿¼man
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/un.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <netinet/in.h>
#define SERVPORT 3333
#define BACKLOG 10
#define MAX_CONNECTED_NO 10
#define MAXDATASIZE 100
int main()
{
/*
struct sockaddr_in {
//µØÖ·×åAF_INET£¨IPv4£©AF_INET6£¨IPv6£©AF_LOCAL£¨UNIXÓòÐÒ飩AF_LINK£¨Á´Â·µØÖ·ÐÒ飩AF_KEY£¨ÃÜÔ¿Ì×½Ó×Ösocket£©AF_APPLETALK£¨ddp£©
¡¡¡¡ short int sin_family;
//¶Ë¿ÚºÅ
¡¡¡¡ unsigned short int sin_port;
*
* struct in_addr {
* unsigned long s_addr;
* }
*
//µØÖ·
struct in_addr sin_addr;
unsigned char sin_zero[8];
}
eg:
struct sockaddr_in ina;
bzero(&ina,sizeof(ina));
ina.sin_family=AF_INET;
ina.sin_port=htons(23);
ina.sin_addr.s_addr = inet_addr("132.241.5.10");
AF_INETºÍPF_INETÂÔÓвîÒì
*/
struct sockaddr_in server_sockaddr,client_sockaddr;
int sin_size,recvbytes;
fd_set readfd;
fd_set writefd;
int sockfd,client_fd;
char buf[MAXDATASIZE];
/*
int socket(int domain, int type, int protocol);
domain:PF_INET...
type:SOCK_STREAM,SOCK_STREAM,SOCK_RAW...
protocol:/etc/protocols tcp,udp...
*/
if((sockfd = socket(AF_INET,SOCK_STREAM,0))==-1){
perror("socket");
exit(1);
}
printf("socket success!,sockfd=%d\n",sockfd);
server_sockaddr.sin_family=AF_INET;
server_sockaddr.sin_port=htons(SERVPORT);
server_sockaddr.sin_addr.s_addr=INADDR_ANY;
//set to 0
bzero(&(server_sockaddr.sin_zero),8);
/*
int bind(int sockfd, const struct sockaddr *my_addr,socklen_t addrlen);
sockfd:created by socket
*my_addr:convert from sockaddr_in
addrlen:sizeof(sockaddr)
*/
if(bind(sockfd,(
Ïà¹ØÎĵµ£º
´´½¨×ÀÃæÍ¼±ê
Ŀǰ½«ÍøÂçÓ¦ÓÃÀ©Õ¹µ½×ÀÃæÊÇÒ»¸öÇ÷ÊÆ£¬´æÔÚןܶà½â¾ö·½°¸£¬±¾ÎÄÒÔ Mozilla Prism ΪÀý£¬ÀàËÆµÄ·½·¨Í¬ÑùÊÊÓÃÓÚ Google Chrome ¡£
1. µ½ Mozilla Prism µÄÍøÕ¾ÉÏÏÂÔØ Prism£¬µã»÷ Download Now Ö®ºó»áÌáʾÓÐÁ½ÖÖ£¬Ò»ÖÖÊÇÒÔ Mozilla Firefox À©Õ¹µÄ·½Ê½£¬ÊʺÏÒѾ°²×°ÓÐ Firefox µÄÅóÓÑ£»Ò»Ö ......
Á´½ÓÎļþÓеãÀàËÆÓÚWindows µÄËùν¿ì½Ý·½Ê½£¬µ«²¢²»ÍêȫһÑù¡£Á´½ÓÓÐÁ½ÖÖ·½Ê½£¬ÈíÁ´½ÓºÍÓ²Á´½Ó¡£
¡¡¡¡ÈíÁ´½ÓÎļþ
¡¡¡¡ÈíÁ´½ÓÓֽзûºÅÁ´½Ó£¬Õâ¸öÎļþ°üº¬ÁËÁíÒ»¸öÎļþµÄ·¾¶Ãû¡£¿ÉÒÔÊÇÈÎÒâÎļþ»òĿ¼£¬¿ÉÒÔÁ´½Ó²»Í¬ÎļþϵͳµÄÎļþ¡£Á´½ÓÎļþÉõÖÁ¿ÉÒÔÁ´½Ó²»´æÔÚµÄÎļþ£¬Õâ¾Í²úÉúÒ»°ã³ÆÖ®Îª"¶ÏÁ´"µÄÎÊÌâ(»òÔ»“ÏÖ ......
ÕâÀï¼ÌÐøÉÏһƪ¹ØÓÚÏ̺߳¯ÊýµÄ½éÉÜ£º
int pthread_detach (pthread_t thread_handle);
Õâ¸öº¯ÊýµÄ×÷ÓÃÊÇÈÃthread_handleÖ¸ÏòµÄÄ¿±êÏß³ÌÔÚÖÐÖ¹µÄʱºòÇåÀí×Ô¼ºÓµÓеÄÊý¾Ý¡£ÔÚÕâ¸öº¯Êýµ÷ÓÃÖ®ºó£¬
²»ÄÜÔÙ¶Ôthread_handleʹÓÃpthread_join¡£
ÏÔ¶øÒ×¼ûµÄÊÇ£¬Èç¹ûÎÒÃÇûÓжÔд´½¨µÄÏ̵߳÷ÓÃpthread_detach£¬Õâ¸öÏß ......
ÔÚlinux»·¾³Ï±à³ÌÓÐÒ»¸öºÜÈÃÈËÍ·ÌÛµÄÎÊÌâ¾ÍÊÇÐźŶÔϵͳµ÷ÓõĸÉÈÅ£¬ÔÚϵͳµ÷Óùý³ÌÖÐÈç¹ûÊܵ½ÐźŵĸÉÈÅ£¬
²¿·Öϵͳµ÷ÓûὫerrnoÉèÖóÉEINTR£¬ÎÒÃDz»µÃ²»±àдÏÂÃæµÄ´íÎó´¦Àí´úÂëÀ´·ÀÖ¹ÕâÖÖÇé¿öµÄ·¢Éú£º
syscall:
int ret = syscall(...);
if (ret < 0 && EINTER == errno)
goto syscall;
el ......
×ªÔØ android sdk 1.5 °²×°ÓëÅäÖÃ
²Î¿¼ ubuntu 8.10 °²×° Android
1.ÏÂÔØandroid sdk
ÏÂÔØµØÖ·ÈçÏ£º
http://dl.google.com/android/android-sdk-windows-1.5_r2.zip
http://dl.google.com/android/android-sdk-linux_x86-1.5_r2.zip
2.
ÏÂÔØeclipse 3.4.2
°´¹Ù·½ÎĵµËµ£¬android sdk ¿ÉÒÔÔËÐÐÔÚ ......