Help with Sockets

Previous topic - Next topic

Omadan

Code (glbasic) Select
// --------------------------------- //
// Project: iPodNet
// Start: Friday, April 13, 2012
// IDE Version: 10.244


// SETCURRENTDIR("Media") // go to media files
SYSTEMPOINTER 1;
SETSCREEN 480,320,1;

GLOBAL mx%,my%,mb1%,mb2%,clicked%;
GLOBAL server%,client%,lastip%,socktcp%,sock%;
GLOBAL ip$="178.208.199.151";
GLOBAL port%=21851;
GLOBAL msg%,readmsg%,connect%;

WHILE NOT KEY(1)
MOUSESTATE mx%,my%,mb1%,mb2%;

//create server or client
IF server=0 AND client=0
IF mb1>=1
IF mx<200//touch left side of screen to create server
CreateServer();
ELSEIF mx>280//touch right side of screen to create client
CreateClient();
ENDIF
ENDIF
ENDIF

TcpListen();

IF server=1
PRINT "ACTING AS SERVER",10,10,1;
ENDIF
IF client=1
PRINT "ACTING AS CLIENT",10,10,1;
ENDIF
IF connect=1
PRINT "CLIENT CONNECTED",10,50,1;
ENDIF

IF mb1=0
clicked=0;
ENDIF
SHOWSCREEN
WEND

FUNCTION TcpListen:
IF server=1//server checks for messages
readmsg=SOCK_TCPACCEPT(socktcp,lastip);
IF readmsg>=1
//client has connected
connect=1;
ENDIF
ENDIF
ENDFUNCTION

FUNCTION CreateServer:
sock=SOCK_INIT();
IF sock
socktcp=SOCK_TCPLISTEN(port);
DEBUG "SERVER:sock=ok ";
IF socktcp>=0
server=1;
DEBUG "SERVER:socktcp=ok ";
ELSE
DEBUG "SERVER:could not create sock ";
ENDIF
ENDIF
ENDFUNCTION

FUNCTION CreateClient:
sock=SOCK_INIT();
IF sock
socktcp=SOCK_TCPCONNECT(ip$,port,5000);
DEBUG "CLIENT:sock=ok ";
IF socktcp>=0
client=1;
DEBUG "CLIENT:socktcp=ok ";
ELSE
DEBUG "CLIENT:could not create sock ";
ENDIF
ENDIF
ENDFUNCTION


Can anyone please help with the above code. I cant verify whats wrong, well actually nothing is wrong because it works perfectly on PC, it just does not work on iPhone when I run it as server.

To clear matters hope this helps

PC Server - PC Client = Works perfect
PC Server - iPod Client = Works perfect
iPod Server - iPod Client = No way
iPod Server - PC Client = No way

Cant get this running on as iPod Server. Yes I have allowed for all ports on PC and iPod, it would not be working on PC then.

I have even disabled firewalls etc, but thats not the problem as it works on PC's, can anyone please help here?

Ill really be thankful.

Thanks

NOTE: Just run program in 2 separate instances, click left side of screen to act as server, and on other click right to act as client.
When you run client you receive msg on server side.
Top Arcade Apps - Best game for mobiles and computers

http://www.toparcadeapps.com

spicypixel

#1
On this line

Code (glbasic) Select
socktcp=SOCK_TCPCONNECT(ip$,port,5000);

You are trying to connect on IP 178.208.199.151 is this your PC's IP address? If it is you need to find out your devices IP. It will differ obviously when using Wifi or 3G. I seem to remember having issues with receiving data on 3G but not sending it. May be wrong there though.
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Omadan

This is the Internet IP address, the number you get in ipchicken.com. This is the number that needs to be used right? It's the only number that can be used for people to connect to you externally. Like I said it works on PC, don't see why it doesn't from iPod.

Thanks
Top Arcade Apps - Best game for mobiles and computers

http://www.toparcadeapps.com

Moebius

Are you having port forwarding issues?  (Presuming you connect using a router, how have you set it up?  Sounds like the port is forwarded to your PC - so connecting to it works, but won't work on another device in your network...)
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary