ios - GCDAsyncSocket: [socket acceptOnPort: error:] not accepting -


so have been trying create 2 gcdasyncsocket's in project, 1 (socket) uploads file server , other (listensocket) waits process server communicate it. in viewcontroller have initialized them in viewdidload method , setup delegate self both sockets.

socket = [[gcdasyncsocket alloc] initwithdelegate:self delegatequeue:dispatch_get_main_queue()]; listensocket = [[gcdasyncsocket alloc] initwithdelegate:self delegatequeue:dispatch_get_main_queue()]; 

i made listensocket start listening by

nserror *err = nil; if (![listensocket acceptonport:19920 error:&err]) {     nslog(@"listensocket failed accept: %@", err); } 

i made socket connect remote server , start uploading files.

the problem socket works fine , can upload , read response server, seems can't access accepting listensocket way. not other process on server, nor using telnet or typing ip address , port number browser. why , how fix it?


edit:

here's doing app:

i working on app programs arduino on iphone. due app store policy compiling , uploading process has on server, i'm using socket upload code server compiled. in order upload compiled binaries arduino, have run avrdude fortunately accept ip + port address instead of usb connection target. avrdude implemented connects address client, have open listening socket on app.

i imagine issue relates device not having routable ip address outside world. have assumed here not testing on local network server , phone both using network via wifi/cable.

when on device using mobile network, assigned ip address mobile operator. address more address part of internal mobile network. when connect outside of mobile network server, address server sees device not address see on device. addresses mapped in transit ip packet passes through various gateways while on way server. when server sees connection requested on listen socket, has reply address when used allows reply traverse device.

a similar issue occurs when device on wifi behind nat router. connections made outgoing seen router , changes ip address of router. since sees start of conversation, know return packets given port , sequencing should routed. if wants connect device outside, have have set port forwarding on router known port telling send connection packets.

so applying situation:

outgoing works (why):

your outgoing socket works, because connecting externally visible ip. when connect, network knows packet has go , reply address provided in packet network.

incoming not work (why):

your listen socket not working because address sending not exist on open internet. make connection server or anywhere else device need ip has routing mapped through device. if device on mobile network, need external ip mobile network maps device. if device behind nat router, need port forwarding set up.

solution:

unfortunately, there no easy solution need ip address device in outside world. depends on use case have not mentioned. either need external ip reliable or need use intermediate server handle messaging or need change approach , have device poll every information.

this problem has existed long time , why peer peer companies have smart algoithms connecting peer peer services use clever techniques hole punching connect devices.

imho move model device initiates connection if can.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -