易截截图软件、单文件、免安装、纯绿色、仅160KB

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,


相关文档:

a5xx 摄像头驱动移植(For Linux 2.6.14)

Spca5xx 摄像头驱动移植(For Linux 2.6.14)
一.下载并解压Spca5xx驱动,本文使用了gspcav1-20070508版本。
二.版本说明:之前尝试过spca5xx*的多个版本,虽然移植没有问题,但是在进行v4l应用时,出现很多莫名其妙的错误,比如ISOC data error等,后来换成了最新的gspca版本,问题全部解决。
三.完整编译移植好的Li ......

Linux指令 文件访问权限

[root@localhost root]# ls -l
会显示目录或文件信息:drwxr-xr-x 2 root root 4096 06-29 14:30 Test
                               -rwxr--r-- 2 root roo ......

Linux下用eclipse写C/C++语言程序的编译问题

当要建立线程等时,在Linux下,用文本编辑,在键入“g++ -lpthread”.......“可以把库pthread引入”,编译通过。现在想用eclipse,但是默认情况下,引入不了pthread。会报“undefined reference to phread_create”等错误。
解决方法:可以在project中好到properties
在里面的&ldquo ......

Linux下C/C++编译器gcc使用简介

1.gcc包含的c/c++编译器
gcc,cc与c++,g++
gcc和cc是一样的,c++和g++是一样的。一般c程序就用gcc编译,c++程序就用g++编译。
2.gcc的基本用法
gcc test.c:如果没有指定输出的文件,默认将编译出一个名为a.out的程序
gcc test.c -o test:-o参数用来指定生成目标程序的名字,这样将编译出一个名为test的程序。
3.为什 ......

Linux下ARM汇编语法

第一部分 Linux下ARM汇编语法
 
      尽管在Linux下使用C或C++编写程序很方便,但汇编源程序用于系统最基本的初始化,如初始化堆栈指针、设置页表、操作 ARM的协处理器等。初始化完成后就可以跳转到C代码执行。需要注意的是,GNU的汇编器遵循AT&T的汇编语法,可以从GNU的站点 (www.g ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号