![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 4
![]() |
Internet connection
I'm trying to figure out how to have a program connect to another program on a different computer, without a server. Just a direct connection. Can someone point me to a good tutorial for this?
|
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
Google is your friend
:http://www.amk.ca/python/howto/sockets/ You will always need a server socket, to accept a connection. This doesn't mean you will need a complete server, though. |
|
|
|
|
|
#3 |
|
Banned
![]() ![]() |
The most secure way, IMO, especially if you're using open-sourced programming (Python), is to go through a server.
I only have experience with the latter though, only small stuff with the socket module, so don't base what I'm saying on any matter. :p |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Server-client networking is no more secure than peer-to-peer networking. Transmission security is just a matter of encryption.
Though I suppose you could argue that a well-known server is more trustworthy than an anonymous peer, assuming the peer is anonymous. |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 4
![]() |
Yes, I know that one of the programs must act as a server; what I meant is no central server on a website somewhere =)
Thanks for the link, polyphemus. |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 4
![]() |
Anyone good with sockets? I can't seem to get them working. Here's my code...
#Server:
import socket
mySocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mySocket.bind((socket.gethostbyname(socket.gethostname()),3867))
mySocket.listen(1)
while True:
channel,details=mySocket.accept()
print 'We have opened a connection with',details
print channel.recv(100)
channel.send('Green-eyed monster.')
channel.close()#Client
import socket
mySocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mySocket.connect(('[IP address]',3867))#Here I actually put my ip address, not just '[IP address]'.All I'm trying to do is just get a connection, but I can't. Can anyone help? EDIT: For some reason it's showing two spaces in the middle of SOCK_STREAM and gethostname(), but those aren't in the code =) |
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Shouldn't your client be sending something? The "print channel.recv(100)" will wait until the connecting client has sent some data down the stream. If your client doesn't send anything, it will wait forever.
|
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 4
![]() |
Right, but my problem is that it's not even printing 'we have a connection with',details; I'm not even getting a connection.
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Try changing this line:
mySocket.bind(( socket.gethostbyname(socket.gethostname() ),3867)) mySocket.bind(('', 3867))On your client side, be aware that if you're behind a NAT, you'll need to talk to your server via it's local IP address (192.168.x.x or 10.x.x.x), or, if it's on the same machine as your server, through localhost (127.0.0.1 or a blank string). |
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 4
![]() |
Well, I'm not trying to connect within the same machine; the Server program is on my computer, but the client is run on a friend's computer. I'm trying to connect across the internet.
Edit: Ah right, I think I read your post wrong. I'll try that. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|