-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// BilibiliSocketClient.h | ||
// bilibili | ||
// | ||
// Created by TYPCN on 2015/5/17. | ||
// Copyright (c) 2015 TYPCN. All rights reserved. | ||
// | ||
|
||
#ifndef bilibili_BilibiliSocketClient_h | ||
#define bilibili_BilibiliSocketClient_h | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface LiveSocket : NSObject | ||
|
||
- (bool)ConnectToTheFuckingFlashSocketServer: (int)roomid; | ||
|
||
@end | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// SocketClient.m | ||
// bilibili | ||
// | ||
// Created by TYPCN on 2015/5/17. | ||
// Copyright (c) 2015 TYPCN. All rights reserved. | ||
// | ||
|
||
#import "BilibiliSocketClient.h" | ||
|
||
#include "Socket.hpp" | ||
|
||
@implementation LiveSocket{ | ||
tcp_client c; | ||
} | ||
|
||
- (bool)ConnectToTheFuckingFlashSocketServer: (int)roomid{ | ||
if(!c.conn("livecmt.bilibili.com" , 88)){ | ||
return false; | ||
} | ||
|
||
NSString *initStr = [NSString stringWithFormat:@"0101000c0000%04x00000000",roomid]; | ||
NSData *data = [self dataFromHexString:initStr]; | ||
c.send_data([data bytes], (int)[data length]); | ||
while(true){ | ||
std::string str = c.receive(1024); | ||
if(str.length() > 0){ | ||
NSLog(@"Data: %s",str.c_str()); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
- (NSData *)dataFromHexString:(NSString *)str { | ||
const char *chars = [str UTF8String]; | ||
int i = 0, len = (int)str.length; | ||
|
||
NSMutableData *data = [NSMutableData dataWithCapacity:len / 2]; | ||
char byteChars[3] = {'\0','\0','\0'}; | ||
unsigned long wholeByte; | ||
|
||
while (i < len) { | ||
byteChars[0] = chars[i++]; | ||
byteChars[1] = chars[i++]; | ||
wholeByte = strtoul(byteChars, NULL, 16); | ||
[data appendBytes:&wholeByte length:1]; | ||
} | ||
|
||
return data; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// LiveChat.h | ||
// bilibili | ||
// | ||
// Created by TYPCN on 2015/5/17. | ||
// Copyright (c) 2015 TYPCN. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface LiveChat : NSViewController | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// LiveChat.m | ||
// bilibili | ||
// | ||
// Created by TYPCN on 2015/5/17. | ||
// Copyright (c) 2015 TYPCN. All rights reserved. | ||
// | ||
|
||
#import "LiveChat.h" | ||
#import "BilibiliSocketClient.h" | ||
|
||
extern NSString *vCID; | ||
|
||
@interface LiveChat () | ||
|
||
@end | ||
|
||
@implementation LiveChat | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
LiveSocket *socket = [[LiveSocket alloc] init]; | ||
|
||
[socket ConnectToTheFuckingFlashSocketServer:[vCID intValue]]; | ||
} | ||
|
||
@end |
Oops, something went wrong.