Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 23rd, 2008, 2:34 AM   #1
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Sockets & IP's

Hi, im new to python just so you know
this maybe hard to explain so if you don't inderstand what im asking just say.

Im am trying to write a scripts that connects to a remote pc, this is not a problem providing i have the IP of the computer. However thecomputer i want to connect to is on a network, so the IP address im having to try to connect to is the routers IP and not the indervidual computers IP. Is there anyway using socket.connect() or another function perhaps to connect to a remote pc on a network.

thanks for any help
Freaky Chris is offline   Reply With Quote
Old Mar 23rd, 2008, 3:22 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Re: Sockets & IP's

If you pass the function you're using the network IP address of the computer, shouldn't the router point you directly to the computer you're looking for?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 23rd, 2008, 3:30 AM   #3
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Sockets & IP's

yes it does for local, but this is remote. As far as im awear you can only pass it one ip address, which firstly must be the address of the remote router from there it needs to specify which computer to connect to on the network.
Freaky Chris is offline   Reply With Quote
Old Mar 23rd, 2008, 3:59 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Re: Sockets & IP's

My recommendation would be to have the router always point to the same PC for the port you're connecting on, and have that PC redirect the query based on the network address you send it.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 23rd, 2008, 4:28 AM   #5
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Sockets & IP's

im looked into that and after configuring the virtual server on my router to forward calls to 4000 to a specified computer on my network and the port that the server script is monitoring however still no luck, im getting a connection timed out error. This may be due to the fact im testing internally although this should affect it.

Any other ideas?
Freaky Chris is offline   Reply With Quote
Old Mar 23rd, 2008, 7:56 AM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Re: Sockets & IP's

Sounds like a problem with your server script. Can we see it?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 23rd, 2008, 11:00 AM   #7
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Sockets & IP's

Sure, just remember it works fine on a local network so im not sure that it is the server script but here. There are a few things that arn't completely tied up as im just testing things out but it basically works.

import socket, sys, threading

def parseIP(ip):
    unparsedIP = ip
    parsedIP = ''
    parsedIP = unparsedIP.replace('(\'', '')
    parsedIP = parsedIP.replace('\',', '')
    parsedIP = parsedIP.replace(')', '')
    x = parsedIP.find(' ')
    parsedIP = parsedIP[:x]
    return parsedIP

def msgclient(client):
    address = myClients[client]
    return address

class server(threading.Thread):
    v = ''
    vlock = threading.Lock()
    id = 0
    
    def __init__(self, clientSock):
        threading.Thread.__init__(self)
        self.myid = server.id
        server.id += 1
        self.myclientsock = clientSock

    def run(self):
        while 1:
            k = self.myclientsock.recv(1000000)
            if k == '/close': break
            elif k == '/show':
                msg = '\n'.join(myClientsNames)
                self.myclientsock.send(msg)
            elif k == '/terminate':
                k = ''
                server.v = ''
                break
            elif k[:5] == '/send':
                t = k.lstrip('/send ')
                q = t.find(' ')
                myClientsSock[((t[:q+1]).rstrip(' ')).title()].send('HELLO')
                print 'HELLO'
                client.send('sent!')
            else:
                server.vlock.acquire()
                server.v += k
                server.vlock.release()
                client.send(server.v)
        myClientsNames.remove(myClients[self.myclientsock])
        del myClientsSock[myClientsNames[myClients[self.myclientsock]]]
        del myClientsIPs[myClientsNames[myClients[self.myclientsock]]]
        self.myclientsock.close()
        
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.bind(('',4000))
sock.listen(5)

noClients = 5
mythreads = []
myClients = {}
myClientsIPs = {}
myClientsNames = []
myClientsSock = {}

for i in range(noClients):
    (client, ap) = sock.accept()
    uName = (client.recv(20)).title()
    myClients[client] = uName
    myClientsIPs[uName] = parseIP(str(ap))
    myClientsNames.append(uName)
    myClientsSock[uName] = client
    newServer = server(client)
    print ap
    mythreads.append(newServer)
    newServer.start()

sock.close()
Freaky Chris is offline   Reply With Quote
Old Mar 24th, 2008, 3:08 AM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Re: Sockets & IP's

Was thinking about this earlier and found out my router doesn't allow external-style access when you're accessing things internally. If you're inside the network, you have to do things one way; if you're outside, you have to do it a different way. Perhaps that's causing the problem? Have you tried accessing it from outside?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 24th, 2008, 4:44 AM   #9
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Sockets & IP's

i did have a feeling that may of been a problem, no i havn't had chance yet but i will a soon as i can.
Did you have a look at my code at all? if so did you see any major errors if not then its ok just wondered

thanks,
Freaky Chris is offline   Reply With Quote
Old Mar 24th, 2008, 5:27 AM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Re: Sockets & IP's

I'm not seeing any problems, though I've only really glanced over it. As you say though, it works fine locally, so there's no real reason it shouldn't work fine Internet-wide.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple BSD Sockets Problem Soulstorm C 16 Mar 7th, 2008 5:02 PM
Sockets Lib King C++ 7 Apr 10th, 2007 7:17 AM
sockets??? dfoled C++ 3 Oct 19th, 2005 8:06 AM
help with sockets, having a client recieve data as well as send. cypherkronis Python 7 Jul 1st, 2005 5:59 PM
Windows sockets programming davidsiaw C 1 Jun 15th, 2005 6:17 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC