本文介绍了iphone tcp连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iPhone和PC之间建立TCP连接.在PC上,QTspServer正在运行并且正在工作(已与其他客户端应用程序进行了测试).

I want to establish tcp connection between iphone and PC. On PC QTspServer is running and working (was tested with other client application).

这是我在iPhone上使用的连接方法:

Here is the connection method i'm using on iphone:

- (IBAction)connectToServer:(id)sender {
    CFReadStreamRef read = NULL;
    CFWriteStreamRef write = NULL;

    NSString *host = @"192.168.1.169";

    CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)host, 1000, &read, &write);
    CFWriteStreamOpen(write);
    int k = 0;
}

PC上的服务器没有反应.任何帮助都是合适的

The server on PC is not reacting. Any help is appropriate

顺便说一句:服务器只不过是带有incomingConnection方法的QTcpServer.这是服务器端的main函数:

By the way: Server is nothing more then a QTcpServer with replemented incomingConnection method. Here is the main function on server side:

int main(int argc, char **argv)
{
QApplication app(argc, argv);
AbstractServer server;
server.listen(QHostAddress::Any, 1000);
QLabel label("Hello server");
label.setFixedSize(400, 400);
label.show();
return app.exec();
}

推荐答案

在将某些内容发送到服务器之后建立连接

The connection is established after something was sent to the server

这篇关于iphone tcp连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 13:36