473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

socket.bind use a name as address

luke14free
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
3 1796
ghostdog74
511 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. serversocket.bind((socket.gethostname(), 80))
  2.  
May 9 '07 #2
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
ghostdog74
511 Expert 256MB
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

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

Similar topics

6
by: Philippe C. Martin | last post by:
Hi, I am following a few tutorial and this howto: ************************************************************* ............ What happens in the web server is a bit more complex. First, the...
4
by: 0k | last post by:
Hi everyone, I am trying to write a small app that sends multicast udp packets using a socket object. I have more than one NIC on my PC and the following code works OK only if I disable all the...
1
by: mjcast | last post by:
I have been working on an ActiveX control in C#. It is packaged in a Windows Control library and the code is in a user control. The control is used as an automation receiver that is used to update a...
1
by: piotrek | last post by:
Hello all. I have a problem and my solution but i have to make sure that it want cause memory problems. i have a class FTP and 'private Socket CONNECTION = null;' Then i have a method PASV()...
1
by: HABJAN ®iga | last post by:
Hello, how can i bind a socket for listen on some port, and all addresses : In the sample i bind myself to localhost(127.0.0.1) on port 5500. It works fine when connecting to localhost, but if...
14
by: DaTurk | last post by:
I am makeing a Multicast server client setup and was wondering what the difference is between Socket.Connect, and Socket.Bind. It may be a stupid question, but I was just curious. Because I...
6
by: Sean | last post by:
Hi Everyone, My apologies for a somewhat dump question but I am really stuck. I have been working on this code for two days straight I am dont know what is wrong with it. when I run the code, All...
0
by: mhetfield | last post by:
Hi, I'm writing a client-server socket program. the client will be an instance of the well-known telnet application. i want to implement a simple authentication between the server and the client. ...
5
by: natambu | last post by:
I have a linux box with multiple ip addresses. I want to make my python client connect from one of the ip addresses. Here is my code, no matter what valid information I put in the bind it always...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.