LINUXÍøÂç±à³Ì,¼òµ¥µÄÁÄÌì³ÌÐò
·þÎñÆ÷¶Ë£º
½¨Á¢socket£¬±¾µØµØÖ·°ó¶¨bind£¬È»ºó½¨Á¢¼àÌý£¬Èç¹ûÓпͻ§¶ËÇëÇóÔòÏìÓ¦Ö®£¬È»ºó½øÐÐÊý¾ÝµÄ·¢ËͺͽÓÊÕ
Ô´´úÂë:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <string.h>
#include <fcntl.h>
#define MAXDATASIZE 100
#define SERVPORT 3333
#define BACKLOG 10//×î´óÁ¬½ÓÊý
#define STDIN 0 //±ê×¼ÊäÈë
int main(void)
{
FILE *fp;
int sockfd,client_fd;//socket.sock_fd¼àÌý,socket.new_fdÊý¾Ý´«Êä
int sin_size;
struct sockaddr_in my_addr,remote_addr;//±¾»úµØÖ·ÐÅÏ¢£¬¿Í»§µØÖ·ÐÅÏ¢
char buf[256]; //ÓÃÓÚÁÄÌìµÄ»º³åÇø
char buff[256];//ÓÃÓÚÊäÈëÓû§ÃûµÄ»º³åÇø
char send_str[256];
int recvbytes;
fd_set rfd_set,wfd_set,efd_set;//±»select¼àÊӵĶÁ£¬Ð´£¬Òì³£´¦ÀíµÄÎļþÃèÊö·û¼¯ºÏ
struct timeval timeout;
int ret;
if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1)
{
perror("socket");
exit(1);
}
/*¶ËÌî³äsockaddr½á¹¹*/
bzero(&my_addr,sizeof(struct sockaddr_in));
my_addr.sin_family=AF_INET;//µØÖ·×å
my_addr.sin_port=htons(SERVPORT);
inet_aton("127.0.0.1",&my_addr.sin_addr);
if(bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr))==-1)
{
perror("bind");
exit(1);
}
if(listen(sockfd,BACKLOG)==-1)
{
perror("listen");
exit(1);
}
sin_size=sizeof(struct sockaddr_in);
if((client_fd=accept(sockfd,(struct sockaddr *)&remote_addr,&sin_size))==-1)
{
perror("accept");
exit(1);
}
fcntl(client_fd,F_SETFD,O_NONBLOCK);//·þÎñÆ÷Ϊ·Ç×èÈû
recvbytes=recv(client_fd,buff,MAXDATASIZE,0);
buff[recvbytes]='\0';
fflush(stdout);
/*Ç¿ÖÆÁ¢¼´ÄÚÈÝ*/
if((fp=fopen("name.txt","a+"))==NULL)
{
printf("can not open filie,exit...\n");
return -1;
}
fprintf(fp,"%s\n",buff);
/*½«Óû§ÃûдÈëname.txtÖÐ*/
while(1)
{
FD_ZERO(&rfd_set);//¶ÁÎļþÃèÊö·ûÇå
Ïà¹ØÎĵµ£º
ÀýÒ»£º·¢ËÍSignaling Packet£º
Signaling CommandÊÇ2¸öBluetoothʵÌåÖ®¼äµÄL2CAP²ãÃüÁî´«Êä¡£ËùÒÔµÃSignaling CommandʹÓÃCID 0x0001.
¶à¸öCommand¿ÉÒÔÔÚÒ»¸öC-frame£¨control frame£©Öз¢ËÍ¡£
Èç¹ûÒªÖ±½Ó·¢ËÍSignaling Command.ÐèÒª½¨Á¢SOCK_RAWÀàÐ͵ÄL2CAPÁ¬½ÓSocket¡£ÕâÑù²ÅÓлú»á×Ô¼ºÌî³äCommand Code£¬Identi ......
Linux½ø³Ì²é¿´
תÔØ×Ô http://www.cnblogs.com/starspace/archive/2008/10/17/1313246.html
¡¡¡¡linuxÊǸö¶àÓû§ÏµÍ³£¬ÓÐʱºòÒ²ÒªÁ˽âÆäËûÓû§ÏÖÔÚÔÚ¸Éʲô£¬ËùÒÔÔÚ±¾½ÚÖл¹½«½Ó´¥¶àÓû§·½ÃæµÄÈÝ¡£Í¬Ê±LinuxÊÇÒ»¸ö¶à½ø³Ìϵͳ£¬¾³£ÐèÒª¶ÔÕâЩ½ø³Ì½øÐÐһЩµ÷ÅäºÍ¹ÜÀí£»¶øÒª½øÐйÜÀí£¬Ê×ÏȾÍÒªÖªÏÖÔڵĽø³ÌÇé¿ ......
ÔÚWindowsÏ°²×°Èí¼þʱ£¬Ö»ÐèÔËÐÐÈí¼þµÄ°²×°³ÌÐò£¨setup¡¢installµÈ£©»òÕßÓÃzipµÈ½âѹËõÈí¼þ½â¿ª¼´¿É°²×°£¬ÔËÐз´°²×°³ÌÐò£¨uninstall¡¢unware¡¢¡°Ð¶ÔØ¡±µÈ£©¾ÍÄܽ«Èí¼þÇå³ý¸É¾»£¬ÍêȫͼÐλ¯µÄ²Ù×÷½çÃ棬¼òµ¥µ½Ö»ÒªÓÃÊó±êÒ»Ö±µã»÷¡°ÏÂÒ»²½¡±¾Í¿ÉÒÔÁË¡£¶øLinuxºÃÏó¾Í²»Ò»ÑùÁË£¬ºÜ¶àµÄ³õѧÕ߶¼±§Ô¹ÔÚLinuxÏ°²×°ºÍжÔØÈí¼þ·Ç³ ......
Ò»¡¢¼ò½é: Linux²Ù×÷ϵͳÖÐ,ÒÔÎļþÀ´±íʾËùÓеÄÂ߼ʵÌåÓë·ÇÂ߼ʵÌå¡£Â߼ʵÌåϵָÎļþÓëĿ¼; ·ÇÂ߼ʵÌåÔò·ºÖ¸Ó²ÅÌ¡¢Öն˻ú¡¢´òÓ¡»úµÈ¡£
Ò»°ã¶øÑÔ,LinuxÎļþÃû³ÆµÄ×é³É³ýÓÉÁ¬Ðø×Öĸ¡¢±êµã·ûºÅ¡¢Êý×ֵȹ¹³ÉÍâ,Öм䲻ÄÜÓпոñ·û¡¢Â·¾¶Ãû³Æ·ûºÅ / »ò # * % & {} [] ¡¡..µÈÓëShellÓйصÄÌØÊâ×Ö·û¡£
LinuxÎļþÏµÍ ......