Basit bir sunucu
Kod:
from socket import *
s = socket(AF_INET,SOCK_STREAM)
s.bind(("localhost",9000))
s.listen(5)
while True:
c,a = s.accept()
print "Gelen bağlantı alındı:", a
c.send("Merhaba %s\n" % a[0])
c.close()
Kod:
c.send("Merhaba %s\n" % a[0])
Kod:
s.bind(("localhost",9000))
Kod:
s.listen(5)
Kod:
c,a = s.accept()
.settimeout() komutu ise zaman aşımını belirler :
Kod:
s.settimeout(5.0)
.accept
Bir bağlantı kabul et. Soket bir adrese bağlanmalı ve bağlantıları dinlemelidir. Dönüş değeri, bağlantının üzerinde veri göndermek ve almak için kullanılabilen yeni bir soket nesnesi ve bağlantının diğer ucundaki sokete bağlanan adresin olduğu bir çifttir .
Kod:
from socket import *
s = socket(family=AF_INET, type=SOCK_STREAM,)
a = s.accept
family = , Soket ailesi.
type= , Soket tipi.
proto = , Soket protokolü.
Kod:
s = socket(family=AF_INET, type=SOCK_STREAM)

