I know I've been told before to use C++ sockets...and I will if this doesn't work out, but that was before I even knew python had sockets.

Now. The problem here if that my socket enabled program seems to work perfectly well on a LAN, but not over the internet (connection seems impossible). I suspect it may be the DSL modem setting its own local IPs (10.0.0.3 etc).

I tried binding the server to the public ip of the modem(after parsing it from an FTP server's welcome message), but it refuses to do so and scolds me with a few lines of red.

The other thing I tried was to set up port forwarding on the router (not sure if I did it right though), but that didn't work.

So is there some way I can structure the code so that the connecting client can bypass the modem and get to my server? Or (and I know this may not be your expertise) is there someway I can force to modem to assign the public IP to my comp?...however dangerous that may be?

Or (and I know this may not be your expertise) is there someway I can force to modem to assign the public IP to my comp?...however dangerous that may be?

Plenty dangerous and don't do it! Firewalls use NAT for a reason. (OK, that was possibly too alarmist, but still...).

Can you post your code? That way it can be clearer whether the issue is with DNS or something else. In principle, sockets should work transparently over networks, including the 'Net.

Jeff

Sorry I took so long to respond

Here is my code:

import socket, cPickle, select, sys, threading, time
from ftplib import FTP
THREADS=[]

class Server(object):
    def __init__(self):
        self.host=''
        self.backlog=5
        self.port = 30000
        self.size = 1048576
        self.server=None
        self.threads = []
    def set_socket(self):
        try:
            self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.server.bind((self.host, self.port))
            self.server.listen(5)
        except:
            self.port+=1
            self.set_socket()
    def run(self):
        self.set_socket()
        alert=[self.server]
        running=1
        while running:
            print "running server on "+get_ip()+" at port "+str(self.port)
            inputready, outputready, exceptready = select.select(alert, [], [])
            print "check 1"
            for soc in inputready:
                print "check 2"
                if soc==self.server:
                    print "check 3"
                    cli = Client(self.server.accept())
                    cli.start()
                    self.threads.append(cli)
 
        self.server.close()
        print "ggk"
        for cli in self.threads:
            cli.join()
 
class Client(threading.Thread):
    def __init__(self, (client, address)):
        threading.Thread.__init__(self)
        self.client=client
        self.address=address
        self.size=1048576
    def run(self):
        running = 1
        while running:
            data = self.client.recv(self.size)
            if data:
                self.client.send(["confirm", 0])
            else:
                self.client.close()
                running=0
         
def get_ip():
    ftp=FTP("garbo.uwasa.fi")
    ftp.login()
    speech=ftp.getwelcome()
    ftp.quit()
    ip=""
    speech=speech[482:]
    while speech[0] != "\n":
        ip+=speech[0]
        speech=speech[1:]
    return ip
    
def send_list(clients):
    client_file=file("clients.dat", "w")
    cPickle.dump(clients, client_file)
    client_file.close()
    client_file=file("clients.dat", "rb")
    ftp=FTP("rotnet.awardspace.com", "rotnet_client", "rottwylaz")
    <A href="ftp://ftp.storbinary("STOR">ftp.storbinary("STOR clients.dat", client_file)
    ftp.quit()
    
def get_list():
    ftp=FTP("rotnet.awardspace.com", "rotnet_client", "rottwylaz")
    <A href="ftp://ftp.retrbinary("RETR">ftp.retrbinary("RETR clients.dat", file("clients.dat", "wb").write)
    ftp.quit()
    data_file=file("clients.dat", "r")
    clients=cPickle.load(data_file)
    data_file.close()
    return clients
    
def print_list():
    clients=get_list()
    for client in clients:
        print "User at "+client[0]+" is connected at port", client[1]
class Printer(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        print_list()
server=Server()
server.run()
This article has been dead for over six months. Start a new discussion instead.