<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>I have a question about socket bind,my program is
follows:</FONT></DIV>
<DIV><FONT color=#0000ff size=2>from socket import *<BR>import select<BR>import
re<BR>import string<BR>import time<BR>import
sys<BR>HOST='10.1.1.27'<BR>PORT=21567<BR>BUFSIZ=1024<BR>ADDR=(HOST,PORT)<BR>ippat=re.compile(r'[0-9]+([.][0-9]+){3}')<BR>udpCliSock=socket(AF_INET,SOCK_DGRAM)<BR>data=""<BR>try:<BR> while
1:<BR> while data=="":<BR>
data=raw_input('ip address:')<BR>
data=data.strip()<BR> if ippat.match(data) is not
None:<BR> break<BR>
else:<BR> print data,"does not like an ip
address"<BR> print "input
again!"<BR> data=""<BR>
udpCliSock.sendto(data,ADDR)<BR> udpCliSock.close()<BR>
HOST=gethostbyname(gethostname())<BR>
ADDR=(HOST,PORT)<BR>
udpCliSock=socket(AF_INET,SOCK_DGRAM)<BR>
udpCliSock.bind(ADDR)<BR> f = udpCliSock.makefile()<BR>
while 1:<BR> (r,w,e) = select.select([f], [], [],
5.0)<BR> if not
r:<BR> print "out of
time!"<BR> break
<BR> else:<BR> data,
addr = udpCliSock.recvfrom(BUFSIZ)<BR> if
data:<BR> print
data<BR> break<BR>
udpCliSock.close()<BR> HOST='10.1.1.27'<BR>
ADDR=(HOST,PORT)<BR> udpCliSock=socket(AF_INET,SOCK_DGRAM)<BR>except
KeyboardInterrupt:<BR>
sys.exit(0)<BR>udpCliSock.close()</FONT></DIV>
<DIV><FONT color=#0000ff size=2></FONT> </DIV>
<DIV><FONT size=2>When I run it,it raise a error:</FONT></DIV>
<DIV><FONT color=#ff0000 size=2>$ python c33.py<BR>ip address:
202.112.237.15<BR>out of time!<BR>Traceback (most recent call last):<BR>
File "c33.py", line 30, in ?<BR>
udpCliSock.bind(ADDR)<BR>socket.error: (112, 'Address already in
use')</FONT></DIV>
<DIV><FONT color=#ff0000 size=2></FONT> </DIV>
<DIV><FONT size=2>Why is it error? How to correct it? Any ideas will be
appreciated!</FONT></DIV>
<DIV><FONT size=2>
Thanks.</FONT></DIV>
<DIV><FONT
size=2>
Edward</FONT></DIV>
<DIV><FONT color=#ff0000></FONT> </DIV>
<DIV><FONT color=#ff0000 size=2></FONT> </DIV></BODY></HTML>