Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Feb 20th, 2006, 5:40 AM   #1
Writlaus
Hobbyist Programmer
 
Writlaus's Avatar
 
Join Date: Nov 2005
Posts: 149
Rep Power: 4 Writlaus is on a distinguished road
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?
Writlaus is offline   Reply With Quote
Old Feb 20th, 2006, 6:10 AM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
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.
Polyphemus_ is offline   Reply With Quote
Old Feb 20th, 2006, 9:22 AM   #3
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
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
Sane is offline   Reply With Quote
Old Feb 20th, 2006, 9:58 AM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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.
Arevos is offline   Reply With Quote
Old Feb 21st, 2006, 6:15 PM   #5
Writlaus
Hobbyist Programmer
 
Writlaus's Avatar
 
Join Date: Nov 2005
Posts: 149
Rep Power: 4 Writlaus is on a distinguished road
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.
Writlaus is offline   Reply With Quote
Old Feb 24th, 2006, 6:57 PM   #6
Writlaus
Hobbyist Programmer
 
Writlaus's Avatar
 
Join Date: Nov 2005
Posts: 149
Rep Power: 4 Writlaus is on a distinguished road
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 =)
Writlaus is offline   Reply With Quote
Old Feb 24th, 2006, 7:04 PM   #7
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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.
Arevos is offline   Reply With Quote
Old Feb 24th, 2006, 7:05 PM   #8
Writlaus
Hobbyist Programmer
 
Writlaus's Avatar
 
Join Date: Nov 2005
Posts: 149
Rep Power: 4 Writlaus is on a distinguished road
Right, but my problem is that it's not even printing 'we have a connection with',details; I'm not even getting a connection.
Writlaus is offline   Reply With Quote
Old Feb 24th, 2006, 7:27 PM   #9
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Try changing this line:
mySocket.bind(( socket.gethostbyname(socket.gethostname() ),3867))
To this:
mySocket.bind(('', 3867))
Python's socket module treats a blank string as equivalent to localhost, or 127.0.0.1. So this tells it to bind to the local socket 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).
Arevos is offline   Reply With Quote
Old Feb 24th, 2006, 8:15 PM   #10
Writlaus
Hobbyist Programmer
 
Writlaus's Avatar
 
Join Date: Nov 2005
Posts: 149
Rep Power: 4 Writlaus is on a distinguished road
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.
Writlaus 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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:27 PM.

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