I'm trying to get my PHP networking backend for PokéGen to send a message to a test script I wrote that just waits for the message and then replies. I think the problem is that the Python script isn't able to be seen from the outside by my public IP address. Is there a way to get the Python script seen from the outside? I already tried port forwarding, but that didn't exactly work.
port forwarding is indeed the solution. I am assuming you are using a regular socket and calling listen()? Much like this example...


Code:
# Echo server program
import socket

HOST = ''                 # Symbolic name meaning the local host
PORT = 50007              # Arbitrary non-privileged port
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()


Or are you using socketserver? Either way, there isn't a "trick" to get it visible. Port forward whatever port you are binding the python script to, thats all you need to do. If that doesn't work, then the problem is either that you misconfigured the port forwarding, or your PHP script isn't working (could be your web host's firewall, if it has one)

Oh, and somethings to watch out for. Don't use low-numbered ports, as those are already "claimed" and some OS's make you jump hurdels to bind to em. Technically, you should only use ports in the 49152–65535 range. ( http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers )
THe port is forwarded and I checked for reserved ports (49152 is default in the program). The Python should be working since I've used tutorials that list things very similar to the code you have. So maybe it is the PHP... Here's the code for the PHP:

Code:
$server=parse_dat($s);
if(!socket_connect($sock, $server['ip'], $server['port']))
   continue;
if(!socket_send($sock, 'ping', 4, 0x100))
   continue;
sleep($timeout);
if(!socket_recv($sock, $buf, 4, 0x100))
   continue;

The socket is created before and used for each server check and closed afterwards. It says that the connection timesout despite my script running and waiting for a connection. Should the script socket be bound to 'localhost' or '' for the address. One returns 0.0.0.0 and the other 127.0.0.1.
When binding/listening, the host is largely irrelevant.

Oh, and how are you creating the socket? In your PHP snippet you don't include that part...

It should be similar to


Code:
sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
That's exactly how it is in the PHP (except the '$' is needed).
Are you sure you are passing it the right IP and such? I'd try hardcoding the IP/port and seeing if that works. Also, try using write and read instead of send and recv (unless you are timing out when connecting, then that wouldn't do anything...)

'twould help if you would also post your python script....

Oh, and just for the hell of it, try using port 80. If your host does have a firewall, port 80 will definitely be open Smile (note: if you are in linux, you must be logged in as root to bind to port 80)

Code:
import socket
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
print s.getsockname()
s.listen(5)
while 1:
   (conn,addr)=s.accept()
   data=conn.recv(4)
   if data=='ping':
      conn.send('pong')
      print 'conn received'
   else:
      print data
   conn.close()

The connection still times out even on port 80. Even hard-coding failed.
Hmm....

OH! Do you have any firewalls enabled? (including the windows XP SP2 one) that would definitely block the connection
I tried disabling McAfee firewall and it still doesn't connect. I even enabled it within the Firewall to open 49152, but it still doesn't connect. Does the PHP socket need to be bound to anything? I tried binding it to 49152, but that just makes the connection timeout right away instead of processing for a minute or two. I don't think there's any other layer of security left except for the server firewall if it has one...
If you are on windows XP SP2 make sure you turn off that firewall too. Go to control panel->Network connections->right click whatever network connection you are using->properties->Advanced->Windows firewall (Settings)->Off Smile

bind() is only for listening, not for connecting
Windows Firewall isn't even enabled. McAfee takes care of everything for me.
Ok, just making sure (it is on by default, after all)
Kirb, if you want to upload your test server to C0 for testing, you can just give it to me...
KermMartian wrote:
Kirb, if you want to upload your test server to C0 for testing, you can just give it to me...

It's worth a try. You'll need to add a servers/ folder in there as well.
http://nerdyproductions.sobertillnoon.com/pokegen/scripts/pokegen.txt
http://nerdyproductions.sobertillnoon.com/pokegen/scripts/funcs.txt
Just give me the URL to access the script and I'll test it from there.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement