linux c socket ¿ª·¢Óë±àÒëʵÀý
ÕâƪÈÕÖ¾»¹ÊÇÏÈ´ÓÒ»¸öÄܹ»ÔËÐÐÆðÀ´µÄÀý×Ó³ö·¢£¬Ò»µ©ÄÜ˳ÀûµÄ¿´µ½³ÌÐòµÄ³É¹¦ÔËÐУ¬ÄÇô½ÓÏÂÀ´µÄʼþÎÒÏëÓ¦¸ÃÊÇÎÊΪʲôÁË£¿ËƺõÕâÑù¸ü¼ÓÈÝÒ×Àí½âºÍÕÆÎÕ¡£
¶ÔÓÚsocket³ÌÐòµÄ¸ÅÄîÕâÀï¾Í²»¶àдÁË£¬µ«ÎÒÏàÐÅ£¬Èç¹ûÄÜ¿´ÍêÕâÕûƪÎÄÕ£¬ÎÒÏàÐŲ»»áÔÙÓÐÕâÑùµÄÒÉÎʵġ£
ÏÂÃ潫±àдһ¸öc/s½á¹¹µÄ³ÌÐò£¬Ö÷Òª¹¦ÄÜÊÇclient½«Ïòserver·¢ËÍһЩÏûÏ¢£¬¶øµ±serverÊÕµ½clientµÄÇëÇóʱ£¬²¢Ïòclient·¢ËÍÒ»Ìõ»ØÓ¦ÐÅÏ¢¡£
server.c´úÂëÈçÏ£º
#include <stdio .h>
#include < stdlib .h>
#include < errno .h>
#include < string .h>
#include < sys /types.h>
#include < netinet /in.h>
#include < sys /socket.h>
#include < sys /wait.h>
#define SERVPORT 3333
#define BACKLOG 10
#define MAXSIZE 1024
int main() {
int sockfd,client_fd;
struct sockaddr_in my_addr;
struct sockaddr_in remote_addr;
//´´½¨Ì×½Ó×Ö
if ((sockfd = socket(AF_INET,SOCK_STREAM,0)) == -1) {
perror("socket create failed!");
exit(1);
}
//°ó¶¨¶Ë¿ÚµØÖ·
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(SERVPORT);
my_addr.sin_addr.s_addr = INADDR_ANY;
bzero(&(my_addr.sin_zero),8);
if (bind(sockfd, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == -1) {
perror("bind error!");
exit(1);
}
//¼àÌý¶Ë¿Ú
if (listen(sockfd, BACKLOG) == -1) {
perror("listen error");
exit(1);
}
while (1) {
Ïà¹ØÎĵµ£º
1£® ÔÚCÓïÑÔÖÐÄÚǶ»ã±à
ÔÚCÖÐÄÚǶµÄ»ã±àÖ¸Áî°üº¬´ó²¿·ÖµÄARMºÍThumbÖ¸Á²»¹ýÆäʹÓÃÓë»ã±àÎļþÖеÄÖ¸ÁîÓÐЩ²»Í¬£¬´æÔÚһЩÏÞÖÆ£¬Ö÷ÒªÓÐÏÂÃ漸¸ö·½Ã棺
a. ²»ÄÜÖ±½ÓÏòPC¼Ä´æÆ÷¸³Öµ£¬³ÌÐòÌøתҪʹÓÃB»òÕßBLÖ¸Áî
b. ÔÚʹÓÃÎïÀí¼Ä´æÆ÷ʱ£¬²»ÒªÊ¹ÓùýÓÚ¸´ÔÓµÄC±í´ïʽ£¬±ÜÃâÎïÀí¼Ä´æÆ÷³åÍ»
c. R12ºÍR13¿ÉÄܱ»±àÒë ......
±¾ÎÄÀ´×Ô:Linux½Ì³Ì -- http://doc.linuxpk.com/53295.html
ÈçÓв»Ã÷°×Ö®´¦£¬»¶Ó²Î¼ÓÉçÇøÌÖÂÛ
1.Linux“Ï߳̔
±ÊÕßÔø¾ÔÚ¡¶»ùÓÚǶÈëʽ²Ù×÷ϵͳVxWorksµÄ¶àÈÎÎñ²¢·¢³ÌÐòÉè¼Æ¡·£¨¡¶Èí¼þ±¨¡·2006ÄêµÚ5~12ÆÚ£©ÖÐÏêϸÐðÊöÁ˽ø³ÌºÍÏ̵߳ÄÇø±ð£¬²¢Ôø¾ËµÃ÷LinuxÊÇÒ»ÖÖ“¶à½ø³Ìµ¥Ï߳̔µÄ²Ù×÷ϵͳ¡£ ......
µ±ÄãÂòÁĘ̈еçÄÔʱ£¬¾õµÃÐÔÄÜ£¬Ëٶȣ¬Ä㶼±È½ÏÂúÒ⣬µ«ÊÇËæ×Åʱ¼äÍÆÒÆ£¬Äã¾õµÃÄãCÅÌ¿Õ¼äÔ½À´Ô½Ð¡£¬ËÙ¶ÈÒ²½µÏÂÁË£¬ÄÇÎÒÃǸÃÔõô°ìÄØ£¿
¶ÔÓÚ²ËÄñÀ´Ëµ£¬ÓÐÒ»µãÄã±ØÐë×¢Ò⣺µ±ÄãÏÂÔض«Î÷£¬ÓÐЩÍøÕ¾ÊÇĬÈÏCÅÌ£¬Õâʱ¿ÉÒÔÑ¡ÔñÏÂÔØÅÌʱ£¬×îºÃ·ÅÔÚÆäËûÅÌÀ²»¿ÉÒÔÑ¡ÔñҲû°ì·¨£¬CÅÌÀïµÄÎļþÒ²ÊDz¡¶¾Ï²»¶ ......
³ÌÐò¿ªÍ·ÒªÉùÃ÷
#include <string.h>
º¯ÊýÃû: stpcpy
¹¦ ÄÜ: ¿½±´Ò»¸ö×Ö·û´®µ½ÁíÒ»¸ö
ÓÃ ·¨: char *stpcpy(char *destin, char *source);
³ÌÐòÀý:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
&n ......
ÊÕ¼¯ÁË¿´Ò»ÏÂC/C++±ê×¼¿âʹÓõÄÏà¹ØÍøÕ¾£º
GNU¹ÙÍø£º
http://www.gnu.org/
¸ÃÍøÕ¾°üº¬C/C++±ê×¼¿âµÄʹÓ÷¶Àý£¬ÖµµÃ²Î¿¼£º
http://www.cplusplus.com/
ÔÚǶÈëʽµÚÈý·½Èí¼þÒÆֲʱ£¬»áʹÓÃSTLÄ£°å¿â×÷ÏàÓ¦ÒÆÖ²£¬ÈçAndroidƽ̨JNI·â×°¼°ÒÆÖ²µÈ¡£
¸ÃÍøÕ¾½éÉÜstlportµÄʹÓã¬stlportÒѿɳɹ¦ÒÆÖ²ÖÁAndroidµÈǶÈëʽƽ̨£¬²¢Ç ......