client-client connection using socket

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
 
L

Laszlo Zsolt Nagy

Hello,

I have two client computers, each has its own host name.
Hello,

I did not understand your problem. I do not see cleary what you want to do?

When you say "client", do you mean a client in a client-server architecture?
Maybe you want to create a peer-to-peer connection -- that is not the same.
#Server program. Could we use client hostname here ?
Of course you can use the client's hostname. But for what purpose?
print "connected from:",addr
You can do a reverse DNS lookup here to get the hostname of the client.
#Client program
Ok, it seems to me that you have one client and one server. Am I wrong?
Do you want to create a connection socket between the two clients?
Is it your problem?


--
_________________________________________________________________
Laszlo Nagy web: http://designasign.biz
IT Consultant mail: (e-mail address removed)

Python forever!
 
D

dcrespo

"Client" and "Server" are just definitions or convention names. If your
program "listens" to connections, then it is a server. Just it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top