#!/usr/bin/env python
from socket import *
import time
import sys
import select
import threading
import Queue
_name_='_main_'
loop=2
def client1_chat(connection1,connection2,i):
while 1:
data1=connection1.recv(1024)
if data1=='end':
end1=data1
connection1.close()
connection2.send('%s' % data1)
break
else:
connection2.send('%s' % data1)
def client2_chat(connection2,connection1,i):
while 1:
data2=connection2.recv(1024)
if data2=='end':
end2=data2
connection2.close()
connection1.send('%s' % data2)
break
else:
connection1.send('%s' % data2)
def main():
i=1
end1=''
end2=''
t1=1
t2=1
myqueue=Queue.Queue()
server_address1 = ('localhost', 21677)
server_address2 = ('localhost', 21678)
server_socket1=socket(AF_INET, SOCK_STREAM)
server_socket2=socket(AF_INET, SOCK_STREAM)
server_socket1.bind(server_address1)
server_socket2.bind(server_address2)
server_socket1.listen(5)
server_socket2.listen(5)
print 'waiting for user connection'
connection1, client_address1 = server_socket1.accept()
print 'new connection from user1::', client_address1
print 'waiting for user connection'
connection2, client_address2 = server_socket2.accept()
print 'new connection from user2::', client_address2
ct1 = threading.Thread(client1_chat,(connection1,connection2))
ct2 = threading.Thread(client2_chat,(connection2,connection1))
ct1.start()
ct2.start()
ct1.join()
ct2.join()
def alive():
t1=ct1.isAlive()
t2=ct2.isAlive()
alive()
if t1 and t2:
alive()
else:
server_socket1.close()
server_socket2.close()
if _name_=='_main_':
main()
Hai friends I am new to python, me trying to write a chat program between two clients through server. Above code is server code I wrote. but it showing assertion error. Please help me to solve it.