By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

socket.bind use a name as address

luke14free
P: 79
Hail,
I am new to web-python and so i would like to ask one thing:

how could i bind my socket to an address like http://thenameiwant or http://www.thenameiwant.somedomain (as i see that medusa ftp server does) ??

could you post a correction of that code as answer?
Expand|Select|Wrap|Line Numbers
  1. import socket,sys
  2. def reply(x):
  3.     sys.stderr.write(x + "\r\n")
  4. mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
  5. mySocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  6. mySocket.bind ( ( 'XXXXXX', 80 ) )#change XXXXXX with an address different
  7. mySocket.listen ( 1 )
  8. print 'Connected!'
  9. while True:
  10.    channel, details = mySocket.accept()
  11.    print 'We have opened a connection with', details
  12.    print channel.recv ( 100 )
  13.    reply('Welcome.')
  14.    channel.send ( 'Welcome.' )
  15.    channel.close()
  16.  
Kind regards,
Luke14free
May 9 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 511
Expand|Select|Wrap|Line Numbers
  1. serversocket.bind((socket.gethostname(), 80))
  2.  
May 9 '07 #2

luke14free
P: 79
Sorry but it doesn't work
1) socketserver-->SocketServer
2)SocketServer has no attribue bind...
3)socket.bind binds it to 'localhost' or '127.0.0.1'or local static ip...
May 10 '07 #3

Expert 100+
P: 511
you don't bind the address to a url. you bind it to your actual server where the web server is installed. gethostname() will get the the server name for you.
please see here for some reference.
May 11 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.