Git Product home page Git Product logo

simpleusbhub's Introduction

该项目基于peertalk封装

https://github.com/rsms/peertalk

使用Pod的话,你需要在Podfile文件里添加以下行:

pod 'PeerTalk', :git => 'https://github.com/rsms/peertalk.git', :commit => '588303b43efa5082d654b6f75d1b84a6ba4b5b9e'

提供两个类:SimpleUSBHubClient、SimpleUSBHubServer

通常将Server部署到移动设备,Client部署到Mac OS

在服务端:

SimpleUSBHubServer* server = [[SimpleUSBHubServer alloc] initWithPort:2345];
[server startWithStateCallback:^(SimpleUSBHubState state) {
	NSLog(@"%d", state);
} receiveCallback:^(uint32_t type, PTData *payload) {
    NSLog(@"receive: %d", type);
    if (type == 102)
    {
    	NSLog(@"收到ping");
    	// 答复,回复pong
    	[self->_server sendFrameOfType:103 withPalload:nil];
    }
}];
_server = server;

在客户端:

SimpleUSBHubClient* client = [[SimpleUSBHubClient alloc] initWithPort:2345];
client.connectInterval = 1.0f;
[client startWithStateCallback:^(SimpleUSBHubState state) {
	NSLog(@"%d", state);
} receiveCallback:^(uint32_t type, PTData *payload) {
    NSLog(@"receive: %d", type);
    if (type == 103)
    {
    	NSLog(@"收到pong");
    }
}];
_client = client;
// 测试,发送ping消息
[self->_client sendFrameOfType:102 withPalload:nil];

你可能需要了解NSData -> dispatch_data_t的使用,来传输数据

效果图:

image-20190507215400090

simpleusbhub's People

Contributors

rexq57 avatar

Forkers

witchan

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.