drrkgbm6851 2016-12-02 08:25
浏览 36

试图让socket.IO-objc使用socket.io的聊天示例php

I am using socket.io's chat example php based (https://github.com/walkor/phpsocket.io) , and I can receive messages. However, I can't send messages. While attempting to set the nickname, I get a crash on the node instance. On the iOS side, I send a message in the socketDidConnect method after my viewDidLoad method...

(void)viewDidLoad  {
    [super viewDidLoad];
     // Do any additional setup after loading the view, typically from a nib.

      self.socketIO = [[SocketIO alloc] initWithDelegate:self];
      self.socketIO.useSecure = NO;

      [self.socketIO connectToHost:@"localhost" onPort:3000];
    }

(void) socketIODidConnect:(SocketIO *)socket{
    NSLog(@"We connected....");
    [self.socketIO sendEvent:@"add user" withData:@"testUser"];
}

On the server side function add user:

  // when the client emits 'add user', this listens and executes
    $socket->on('add user', function ($username) use($socket){
        global $usernames, $numUsers;
        // we store the username in the socket session for this client
        $socket->username = $username;
        // add the client's username to the global list
        $usernames[$username] = $username;
        ++$numUsers;
        $socket->addedUser = true;
        $socket->emit('login', array( 
            'numUsers' => $numUsers
        ));
        // echo globally (all clients) that a person has connected
        $socket->broadcast->emit('user joined', array(
            'username' => $socket->username,
            'numUsers' => $numUsers
        ));
    });

How i can set username and send messages?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度