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) {
Ïà¹ØÎĵµ£º
ÎÄÕÂÀ´Ô´£ºhttp://dev.yesky.com/468/7601968.shtml
2007-10-12 11:01×÷ÕߣºËᦻª³ö´¦£ºÌ켫ÍøÈí¼þƵµÀÔðÈα༣º·½ÖÛ
1.LinuxÎļþϵͳ
¡¡¡¡LinuxÖ§³Ö¶àÖÖÎļþϵͳ£¬Èçext¡¢ext2¡¢minix¡¢iso9660¡¢msdos¡¢fat¡¢vfat¡¢nfsµÈ¡£ÔÚÕâЩ¾ßÌåÎļþϵͳµÄÉϲ㣬LinuxÌṩÁËÐéÄâÎļþϵͳ£¨VFS£©À´Í³Ò»ËüÃǵÄÐÐΪ£¬ÐéÄâÎļþϵͳΪ ......
³ÌÐò¿ªÍ·ÒªÉùÃ÷
#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 ......
×öWindows³ÌÐò¿ª·¢£¬windows APIÒ»¶¨ÊÇҪѧϰµÄ¡£ËäÈ»ÏÖÔÚwindowsƽ̨ϵĿª·¢»·¾³Óкܶ࣬ҲºÜ·½±ã£¬µ«Í¨³£Ö»»áÌṩ
windows·þÎñµÄÒ»¸ö×Ó¼¯£¬ÓÐЩÌØÐÔ»¹µÃµ÷ÓÃAPI¡£
·Ö²ãÊÇÈí¼þ¿ª·¢ÖÐÒ»¸öÓÀ¾ÃµÄ½â¾ö·½°¸£¬ºÜ¶àÄÑÒÔ½â¾öµÄÎÊÌⶼ¿ÉÒÔÓöà¼ÓÒ»²ãÀ´½â¾ö¡£²Ù×÷ϵͳ¾ÍÊÇÒ»¸öºÜºÃµÄÀý×Ó¡£²Ù×÷ϵͳÔÚ
Èí¼þ¿ª·¢ÈËÔ±Óë¼ÆËã»úÓ²¼þÖ ......