linux socket±à³Ì»ùÓÚ±¾µØunixÓò¸ñʽµÄÐÒé×å
Í·Îļþ£º
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/select.h>
·þÎñÆ÷¶Ë´úÂ룺
int main(int argc, char **argv)
{
struct sockaddr_un address;
int sock, conn;
int addrLength;
char buf[1024] = {0};
char *msg = "I has recived";
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
perror("socket");
exit(0);
}
unlink("foo.sock");
address.sun_family = AF_UNIX;
strcpy(address.sun_path, "foo.sock");
addrLength = sizeof(address.sun_family) + strlen(address.sun_path);
if(bind(sock, (struct sockaddr *) &address, addrLength))
perror("bind");
if(listen(sock, 5))
perror("listen");
while((conn = accept(sock, (struct sockaddr *) &address, &addrLength)) >= 0)
{
recv(conn, buf, sizeof(buf), 0);
printf("%s\n", buf);
send(conn, msg, strlen(msg), 0);
}
return 0;
}
¿Í»§¶Ë´úÂ룺
int main(int argc, char **argv)
{
int client_fd;
int len;
ssize_t I;
char *msg = "hello server";
char buf[1024] = {0};
struct sockaddr_un remote;
if((client_fd = socket(AF_LOCAL, SOCK_STREAM, 0)) == -1)
{
perror("socket()");
exit(0);
}
remote.sun_family = AF_LOCAL;
strcpy(remote.sun_path, SOCK_PATH);
len = sizeof(remote);
//puts("hello, hello, hello, hello");
if(connect(client_fd, (struct sockaddr *)&remote,
Ïà¹ØÎĵµ£º
Spca5xx ÉãÏñÍ·Çý¶¯ÒÆÖ²£¨For Linux 2.6.14£©
Ò»£®ÏÂÔØ²¢½âѹSpca5xxÇý¶¯£¬±¾ÎÄʹÓÃÁËgspcav1-20070508°æ±¾¡£
¶þ£®°æ±¾ËµÃ÷£ºÖ®Ç°³¢ÊÔ¹ýspca5xx*µÄ¶à¸ö°æ±¾£¬ËäÈ»ÒÆÖ²Ã»ÓÐÎÊÌ⣬µ«ÊÇÔÚ½øÐÐv4lÓ¦ÓÃʱ£¬³öÏֺܶàĪÃûÆäÃîµÄ´íÎ󣬱ÈÈçISOC data errorµÈ£¬ºóÀ´»»³ÉÁË×îеÄgspca°æ±¾£¬ÎÊÌâÈ«²¿½â¾ö¡£
Èý£®ÍêÕû±àÒëÒÆÖ²ºÃµÄLi ......
ÔÎĵØÖ·£ºhttp://soft.yesky.com/os/lin/326/2237826.shtml
±¾ÎÄÏêϸµØ½éÉÜÁËÔÚ Linux 2.6.13 ÄÚºËÖÐÐÂÒýÈëµÄÎļþϵͳ±ä»¯Í¨Öª»úÖÆ inotify£¬²¢¾ÙÀý˵Ã÷ÁËËüµÄʹÓÃÓëµäÐÍÓ¦Óð¸Àý¡£
Ò»¡¢ÒýÑÔ
ÖÚËùÖÜÖª£¬Linux ×ÀÃæÏµÍ³Óë MAC »ò Windows Ïà±ÈÓÐÐí¶à²»ÈçÈËÒâµÄµØ·½£¬ÎªÁ˸ÄÉÆÕâÖÖ×´¿ö£¬¿ªÔ´ÉçÇøÌá³öÓû§Ì¬ÐèÒªÄÚºËÌṩ ......
ʲôʱºòÐèÒª´´½¨Ï̳߳ØÄØ£¿¼òµ¥µÄ˵£¬Èç¹ûÒ»¸öÓ¦ÓÃÐèҪƵ·±µÄ´´½¨ºÍÏú»ÙỊ̈߳¬¶øÈÎÎñÖ´ÐеÄʱ¼äÓַdz£¶Ì£¬ÕâÑùÏ̴߳´½¨ºÍÏú»ÙµÄ´øÀ´µÄ¿ªÏú¾Í²»ÈݺöÊÓ£¬ÕâʱҲÊÇÏ̳߳ظóö³¡µÄ»ú»áÁË¡£Èç¹ûÏ̴߳´½¨ºÍÏú»Ùʱ¼äÏà±ÈÈÎÎñÖ´ÐÐʱ¼ä¿ÉÒÔºöÂÔ²»¼Æ£¬ÔòûÓбØÒªÊ¹ÓÃÏ̳߳ØÁË¡£ÏÂÃæÊÇLinuxϵͳÏÂÓÃCÓïÑÔ´´½¨µÄÒ»¸öÏ̳߳ء£Ïß³Ì³Ø ......
µÚ1ÕÂ×Ö·û²âÊÔº¯Êýisalnum(²âÊÔ×Ö·ûÊÇ·ñΪӢÎÄ×Öĸ»òÊý×Ö)isalpha(²âÊÔ×Ö·ûÊÇ·ñΪӢÎÄ×Öĸ)isascii(²âÊÔ×Ö·ûÊÇ·ñΪASCIIÂë×Ö·û)isblank(²âÊÔ×Ö·ûÊÇ·ñΪ¿Õ¸ñ×Ö·û)iscntrl(²âÊÔ×Ö·ûÊÇ·ñΪASCIIÂëµÄ¿ØÖÆ×Ö·û)isdigit(²âÊÔ×Ö·ûÊÇ·ñΪ°¢À²®Êý×Ö)isgraph(²âÊÔ×Ö·ûÊÇ·ñΪ¿É´òÓ¡×Ö·û)islower(²âÊÔ×Ö·ûÊÇ·ñΪСдӢÎÄ×Öĸ)isprint(² ......
Telnet·þÎñµÄÅäÖò½ÖèÈçÏÂ:
Ò»¡¢°²×°TelnetÈí¼þ°ü(ͨ³£ÒªÁ½¸ö£©
¡¡¡¡1¡¢ Telnet-clIEnt (»ò Telnet)£¬Õâ¸öÈí¼þ°üÌṩµÄÊÇ Telnet ¿Í»§¶Ë³ÌÐò£»
¡¡¡¡2¡¢ Telnet-server £¬Õâ¸öÈí¼þ°üÌṩµÄÊÇ Telnet ·þÎñÆ÷¶Ë³ÌÐò£»
¡¡¡¡°²×°Ö®Ç°Ïȼì²âÊÇ·ñÕâЩÈí¼þ°üÒѰ²×°£¬·½·¨ÈçÏ£º
¡¡¡¡[root@echo root]# ......