May 5, 2009 at 7:47pm UTC
hi ... I have written a simple Relay program in PYTHON in linux
now i need it in c language using by linux
can you help please?
This is the code:
#!/usr/bin/python
import socket
host=''
port=5678
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bond((host,port))
while 1:
print 'Listening on port', port, '...'
s.listen(2)
conn1,addr1=s.accept()
print 'first client connected from ', addr1
conn1.send('Chat relay server ready \n')
conn1.send('You are first client. Please wait...\n')
conn2,addr2= s.accept()
print 'second client connected from ', addr2
conn2.send('Chat relay server ready.\n')
conn2.send('you are second client.\n')
conn1.send('Go ahead!\n')
while 1:
data=conn1.recv(200)
if data:
print '1st > ',data
conn2.send(data)
if data=='bye':break
data= conn2.recv(200)
if data:
print'2nd > ',data
conn1.send(data)
if data=='bye': break
conn1.close()
conn2.close()
May 5, 2009 at 9:54pm UTC
This is the C++ forum, not a C forum. The Boost Asio Library has examples on how to do this in C++ with Boost Asio. Otherwise, grab the Unix Network Programming books by Stephens.