![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
|
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 |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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?
|
|
|
|
|
|
#3 |
|
Professional Programmer
|
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.
|
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
|
|
#5 |
|
Professional Programmer
|
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? |
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Re: Sockets & IP's
Sounds like a problem with your server script. Can we see it?
|
|
|
|
|
|
#7 |
|
Professional Programmer
|
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() |
|
|
|
|
|
#8 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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?
|
|
|
|
|
|
#9 |
|
Professional Programmer
|
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, |
|
|
|
|
|
#10 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |