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);
}
&n
Ïà¹ØÎĵµ£º
ÏÖÔڵĹ«Ë¾ÕÐƸ,¶¼Òª±ÊÊÔÃæÊÔ.Èç¹ûÄã²»ÊÇÄÇÖÖ±à³Ì¹¦µ×·Ç³£ÉîºñµÄÈË,ÓÖ²»ºÃºÃ×¼±¸Ò»·¬,ÔÚ±ÊÊÔÃæÊÔÖÐÍùÍù»á´¦ÓÚ±»¶¯¾ÖÃæ.ËäÈ»ÓÐЩ±ÊÊÔÌâÊǹÊÒâΪÄÑÎÒÃÇ£¬Óеã×êÅ£½Ç¼â.µ«ÊǺܶà±ÊÊÔÌâÃæÊÔÌâȷʵÄܹ»ºÜºÃµØ¿´³öÎÒÃǵĻù´¡. ÔÚÕâÀï,ÎÒ¾ÍÂÔÈ¥ÄÇЩ×êÅ£½Ç¼âµÄÌâ.´ÓcsdnÂÛ̳ÎÒ½ü°ëÄêµÄÊÕ¼¯ÖÐÑ¡³ö10µÀÓдú±íÐÔµÄÌâÄ¿,ÄѶȻù±¾ÉÏÊÇÖ ......
VS2005Öмì²âºÍ¸üÕý C/C++ ´úÂëȱÏÝ
2006-11-26 15:55
VS2005ÖÐÌṩµÄ¼ì²â·½·¨:
1 IDE£¨¼¯³É¿ª·¢»·¾³£©¼¯³É
2 #pragma Ö§³Ö
3 Åú×¢Ö§³Ö
4 ×÷ΪǩÈë²ßÂÔµÄÒ»²¿·ÖÔËÐзÖÎö¹¤¾ß
5 Team System Óë Team Build µÄ¼¯³É
6 ÃüÁîÐÐÖ§³Ö
Ò» ´úÂë·ÖÎö¹¤¾ßÓÃÓÚ¼ì²â³£¼ûµÄ±àÂë´íÎó£¬ÀýÈ绺³åÇøÒç³ö¡¢ÄÚ´æδ³õʼ»¯¡¢¿ÕÖ¸Õë ......
C/C++ÖеÄÈÕÆÚºÍʱ¼ä
ͻ񻣼
±¾ÎÄ´Ó½éÉÜ»ù´¡¸ÅÄîÈëÊÖ£¬Ì½ÌÖÁËÔÚC/C++ÖжÔÈÕÆÚºÍʱ¼ä²Ù×÷ËùÓõ½µÄÊý¾Ý½á¹¹ºÍº¯Êý£¬²¢¶Ô¼Æʱ¡¢Ê±¼äµÄ»ñÈ¡¡¢Ê±¼äµÄ¼ÆËãºÍÏÔʾ¸ñʽµÈ·½Ãæ½øÐÐÁ˲ûÊö¡£±¾ÎÄ»¹Í¨¹ý´óÁ¿µÄʵÀýÏòÄãչʾÁËtime.hÍ·ÎļþÖÐÉùÃ÷µÄ¸÷ÖÖº¯ÊýºÍÊý¾Ý½á¹¹µÄÏêϸʹÓ÷½·¨¡£
¹Ø¼ü×Ö£º
UTC£¨ÊÀ½ç±ê׼ʱ¼ä£©£¬Calendar Ti ......
1¡¢¾Ö²¿±äÁ¿ÄÜ·ñºÍÈ«¾Ö±äÁ¿ÖØÃû£¿ ¡¡
¡¡´ð£ºÄÜ£¬¾Ö²¿»áÆÁ±ÎÈ«¾Ö¡£ÒªÓÃÈ«¾Ö±äÁ¿£¬ÐèҪʹÓÃ"::" ;¾Ö²¿±äÁ¿¿ÉÒÔÓëÈ«¾Ö±äÁ¿Í¬Ãû£¬ÔÚº¯ÊýÄÚÒýÓÃÕâ¸ö±äÁ¿Ê±£¬»áÓõ½Í¬ÃûµÄ¾Ö²¿±äÁ¿£¬¶ø²»»áÓõ½È«¾Ö±äÁ¿¡£¶ÔÓÚÓÐЩ±àÒëÆ÷¶øÑÔ£¬ÔÚͬһ¸öº¯ÊýÄÚ¿ÉÒÔ¶¨Òå¶à¸öͬÃûµÄ¾Ö²¿±äÁ¿£¬±ÈÈçÔÚÁ½¸öÑ»·ÌåÄÚ¶¼¶¨ÒåÒ»¸öͬÃûµÄ¾Ö²¿±äÁ¿£¬¶øÄÇ ......