Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python套接字未将数据返回到ios NSURLConnection_Python_Ios_Objective C_Sockets_Nsurlconnection - Fatal编程技术网

Python套接字未将数据返回到ios NSURLConnection

Python套接字未将数据返回到ios NSURLConnection,python,ios,objective-c,sockets,nsurlconnection,Python,Ios,Objective C,Sockets,Nsurlconnection,我尝试制作一个简单的python服务器,当连接时返回一个字符串: import socket HOST = '' PORT = 8080 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr while 1: data = conn.

我尝试制作一个简单的python服务器,当连接时返回一个字符串:

import socket

HOST = ''                 
PORT = 8080
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
    data = conn.recv(1024)
    if not data: break
    conn.send(data)
conn.close()
我试着用一个简单的连接来连接这个

    NSString *post = @"test";
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:@"http://localhost:8080"]];

    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];

    //NSURLResponse *response;
    //NSError *err;
    NSURLConnection* conn = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];
    [conn start];

    return YES;
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{

}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{

}
在python应用程序中,我得到了connected by的打印结果,但是我在objective c中的委托方法没有被调用。任何指点都很好,谢谢