易截截图软件、单文件、免安装、纯绿色、仅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,


相关文档:

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.为什 ......

Ubuntu linux下安装Eclipse PDT步骤

在Ubuntu Linux下进行PHP开发,首先可以安装搭建 LAMP 环境和 phpmyadmin 这个Mysql 数据库管理工具,之后选择一个FTP传工具如:Filezilla,最后我们还要选择PHP开发工具,Ubuntu自带的Gedit纯文本编辑做一般的代码文本的修改足够,但要实现一些项目和调试等功能就不行了,所以我们还是最好还是选择一款IDE开发环境,这里我 ......

Linux”特派大使”进入中国






<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
    此前,中国的
Linux“
产业”并未与国际
Linux
运动正式接轨,自行其是。但是,从此以后,情况就不同了。为什么?
 
       5

10
日,国际
Linu ......

Linux下ARM汇编语法

第一部分 Linux下ARM汇编语法
 
      尽管在Linux下使用C或C++编写程序很方便,但汇编源程序用于系统最基本的初始化,如初始化堆栈指针、设置页表、操作 ARM的协处理器等。初始化完成后就可以跳转到C代码执行。需要注意的是,GNU的汇编器遵循AT&T的汇编语法,可以从GNU的站点 (www.g ......

ARM 与嵌入式linux的入门建议

原文出处:http://blog.mcuol.com/User/hzami/Article/8116_1.htm
由于很多人总问这个问题,所以这里做一个总结文档供大家参考。这里必须先说明,以下的步骤都是针对Linux系统的,并不面向WinCE。也许你
会注意到,现在做嵌入式的人中,做linux研究的人远比做WinCE的人多,很多产家提供的资料也是以linux为主。我一直很难 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号