简体   繁体   English

尝试将iPod touch连接到我的服务器时网络超时

[英]Network time out when trying to connect ipod touch to my server

I have an ipod touch program that should receive messages from a server program on my mac. 我有一个ipod touch程序,该程序应从Mac上的服务器程序接收消息。 To make sure that the touch can receive messages from a computer other than a mac, I programmed the server in C++. 为了确保触摸可以从Mac以外的其他计算机接收消息,我使用C ++对服务器进行了编程。 If I run both the server and the ipod app on the same computer (the app running on the simulator), the connection is fine and everything is dandy. 如果我在同一台计算机(模拟器上运行的应用程序)上同时运行服务器和ipod应用程序,则连接正常,一切正常。 However, when I try to connect to the server from my device, the connection times out. 但是,当我尝试从设备连接到服务器时,连接超时。 Can anyone spot the problem? 谁能发现问题? I'm not too good with networking, and the iPhone OS in general. 我对网络和iPhone OS不太满意。

server.cpp: server.cpp:

sockfd = socket(PF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
    cout << "ERROR opening socket";
    return;
}

memset((char *)&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);

if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
    cout << "ERROR on binding";
    return;
}

listen(sockfd,5);
clilen = sizeof(cli_addr);

newsockfd = accept(sockfd,(struct sockaddr *) &cli_addr, (socklen_t*)&clilen);
if (newsockfd < 0) {
    cout << "ERROR on accept.";
    return;
}

The server gets stuck at the accept(), waiting for the app... 服务器卡在accept()上,等待应用程序...

client.m: client.m:

CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)hostName, portNum, &readStream, &writeStream);

if (readStream && writeStream) {
    NSLog(@"Starting streams");

    CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
    CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);

    inputStream = (NSInputStream *)readStream;
    [inputStream retain];
    [inputStream setDelegate:self];
    [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [inputStream open];

    outputStream = (NSOutputStream *)writeStream;
    [outputStream retain];
    [outputStream setDelegate:self];
    [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [outputStream open];
}
if (readStream)
    CFRelease(readStream);

if (writeStream)
    CFRelease(writeStream);

As far as I can tell, neither server nor client reports any errors (I'm checking through errno and NSError) other than timing out. 据我所知,服务器和客户端都没有报告任何超时(我正在通过errno和NSError检查)。

If anyone can help me with this, much thanks! 如果有人可以帮助我,非常感谢!

The iPod was connected to a different network than my Mac, and that's why it got blocked. iPod连接到与Mac不同的网络,这就是为什么它被阻止的原因。 When I connected to the same network, it works perfectly fine. 当我连接到同一网络时,它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用boost :: asio连接到SOCKS 5服务器,但我的连接请求格式错误 - Trying to connect to a SOCKS 5 server using boost::asio but my connection request turns out malformed 尝试使用OTL连接到我的PostgreSQL服务器 - Trying to use OTL to connect to my PostgreSQL server 无法连接到本地网络中的服务器 - cant connect to server in local network 与PC的ipod同步(在ipod touch中移动文件) - Ipod Synchronization with PC (moving files to and from an ipod touch) 尝试以阻塞模式将QTcpSocket连接到其自己的QTcpServer时,单线程应用程序可能会超时吗? - May a single-threaded application time out trying to connect a QTcpSocket to its own QTcpServer in blocking mode? 执行客户端时没有服务器OnAccept通知第二次连接 - No server OnAccept notification when doing client Connect a second time Python Websockets:尝试连接到Docker容器中的服务器时出现“格式错误的HTTP消息” - Python websockets: “Malformed HTTP message” when trying to connect to server in Docker container 尝试加载文件时出现运行时错误:矢量下标超出范围? - Getting Run-Time error when trying to Load a file : Vector subscript out of range? 尝试映射网络驱动器时网络不可用错误 - Network Not Available Error when trying to map network drive 试图写std:out并同时归档 - trying to write std:out and file at the same time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM