A
ajikoe
Hello,
I have two client computers, each has its own host name.
Can I do connection like socket between the two?
I check when we want to make connection we have to only put hostname
and port.
For example:
#Server program. Could we use client hostname here ?
HOST = ""
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST,PORT)
tcpSerSock = socket(AF_INET,SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)
while 1:
print "waiting for connection..."
tcpCliSock,addr = tcpSerSock.accept()
print "connected from:",addr
while 1:
data = tcpCliSock.recv(BUFSIZE)
if not data:break
tcpCliSock.send("[%s] %s" % ctime(time()),data)
tcpCliSock.close()
tcpSerSock.close()
#Client program
HOST = "fstbpc19"
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST,PORT)
tcpCliSock = socket(AF_INET,SOCK_STREAM)
tcpCliSock.connect(ADDR)
while 1:
data = raw_input("> ")
if not data:break
tcpCliSock.send(data)
data = tcpCliSock.recv(1024)
if not data:break
print data
tcpCliSock.close()
Sincerely Yours,
Pujo Aji
I have two client computers, each has its own host name.
Can I do connection like socket between the two?
I check when we want to make connection we have to only put hostname
and port.
For example:
#Server program. Could we use client hostname here ?
HOST = ""
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST,PORT)
tcpSerSock = socket(AF_INET,SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)
while 1:
print "waiting for connection..."
tcpCliSock,addr = tcpSerSock.accept()
print "connected from:",addr
while 1:
data = tcpCliSock.recv(BUFSIZE)
if not data:break
tcpCliSock.send("[%s] %s" % ctime(time()),data)
tcpCliSock.close()
tcpSerSock.close()
#Client program
HOST = "fstbpc19"
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST,PORT)
tcpCliSock = socket(AF_INET,SOCK_STREAM)
tcpCliSock.connect(ADDR)
while 1:
data = raw_input("> ")
if not data:break
tcpCliSock.send(data)
data = tcpCliSock.recv(1024)
if not data:break
print data
tcpCliSock.close()
Sincerely Yours,
Pujo Aji