Giter Site home page Giter Site logo

communicator's Introduction

Socket Communicator

  • 利用 socket 实现 客户端-服务器-客户端 的通信

具体功能

客户端

  • a) 连接:请求连接到指定地址和端口的服务端
  • b) 断开连接:断开与服务端的连接
  • c) 获取时间: 请求服务端给出当前时间
  • d) 获取名字:请求服务端给出其机器的名称
  • e) 活动连接列表:请求服务端给出当前连接的所有客户端信息(编号、IP地址、端口等)
  • f) 发消息:请求服务端把消息转发给对应编号的客户端,该客户端收到后显示在屏幕上
  • g) 退出:断开连接并退出客户端程序

服务器

  • a) 向客户端传送服务端所在机器的当前时间
  • b) 向客户端传送服务端所在机器的名称
  • c) 向客户端传送当前连接的所有客户端信息
  • d) 将某客户端发送过来的内容转发给指定编号的其他客户端
  • e) 采用异步多线程编程模式,正确处理多个客户端同时连接,同时发送消息的情况

主要数据结构

服务器端的客户端列表

//客户端结构
struct client
{
    int id;
    int rfd, sfd;   //接受端、发送端socket标志符
    struct sockaddr_in c_addr;  //客户端socket网络地址
    char rbuf[1024], sbuf[1024];    //接受端、发送端缓存区
    pthread_t s_process, r_process; //接受端、发送端线程
}c[10]; //所有客户端结构数组

网络地址

struct sockaddr_in
{
    short sin_family;   //协议类型,用AF_INET
    unsigned short sin_port;    //端口号
    struct in_addr sin_addr;    //ip地址
    unsigned char sin_zero[8];  //作用不大不用管
}

数据包

char pck[3][];
//  type: pck[0]: 功能类型,有以下几种选项
//      1. disconnect:断开连接
//      2. time:获取时间
//      3. server_info:获取服务器信息
//      4. client_list:获取连接客户端列表
//      5. msg:发消息给其他客户端
//  content: pck[1]:包的内容文本,功能功能1-4可填空字符串,功能5必填
//  url: pck[2]:包的转发地址,功能1-4可填空字符串,功能5必填
//  send和recv的时候强制类型转换发送

communicator's People

Watchers

 avatar  avatar

Forkers

devilogier

communicator's Issues

这个程序怎么运行起来?

我现在的需求是两个客户端,一个服务端,两个客户端之间可以通信发文件。并且要在linux下用makefile编译。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.