菜鸟教程小白 发表于 2022-12-11 18:18:00

ios - swift - 我可以连接到 socket.io 服务器,但我不能发出事件


                                            <p><p>我是 socket.io 的初学者
现在我可以连接到套接字服务器和服务器记录我的连接
但我无法向服务器发出事件
这是我的代码:</p>

<pre><code> let socket =SocketIOClient(socketURL: URL(string: &#34;http://xxxxxxx:3000&#34;)!)
    socket.connect()
   let username = &#34;yay&#34;
    socket.emit(&#34;add&#34;, username)
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我终于解决了这个问题:</p>

<pre><code>socket.on(&#34;connect&#34;)
      {data, ack in
            print(&#34;socket connected&#34;)



            socket.emit(&#34;chat message&#34;,myJSON)

      }
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - swift - 我可以连接到 socket.io 服务器,但我不能发出事件,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/45126249/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/45126249/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - swift - 我可以连接到 socket.io 服务器,但我不能发出事件