Saturday, June 23, 2012

#Coding Galau

:D


#!/usr/bin/python
#server program
#Creator : Coder
#buat koneksikan server ke client
#berupa login shell


from socket import *
import threading
import time


# ngeset socket parameter
cintaku = "75.134.61.245"
rindumu = 21568
aku = 21567
kamu = 1024
walau = 1024
jarak = (cintaku,rindumu)

# buat koneksi bind ke port
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(jarak)

katakan,jarak = UDPSock.recvfrom(kamu)
client = katakan
jarak = (client, aku)
katakan,jarak = UDPSock.recvfrom(kamu)
if katakan == "Tersambung...":
                             katakan = "Ya"
                             (UDPSock.sendto(katakan,jarak))
                 print client, "Proses login"

# pesan di terima
while 1:
        katakan,jarak = UDPSock.recvfrom(kamu)
        if not katakan:
        print "klien logout"
        break

        else:
        katakan = "Users/" + katakan + ".txt"
        f = open(katakan,"r")
        lineList = f.readlines()
        f.close()
        merindukanku = katakan
        merindukanku = "username: " + katakan + "\n"
        if merindukanku == lineList[0]:
                  katakan,jarak = UDPSock.recvfrom(kamu)
                  password = "password: " + katakan + "\n"
                  if password == lineList[1]:
                                print merindukanku,"Anda Telah LogIn"
                            katakan = merindukanku
                            (UDPSock.sendto(katakan,jarak))
                            katakan = "-=[selamat datang...]=-"
                            (UDPSock.sendto(katakan,jarak))
                                while 1:
                                class receiver(threading.Thread) :
                                    def __init__(self, socket ):
                                          threading.Thread.__init__(self)
                                          self.setDaemon(True)  
                                     def run(self) :
                                          while True :                          
                                                katakan,jarak = UDPSock.recvfrom(kamu)
                                                if not katakan : break
                                                print katakan
                                          UDPSock.close()
                                receiver(UDPSock).start()
                                while True :                                
                                       katakan = time.ctime() + " Mradr: " + raw_input()
                                       (UDPSock.sendto(katakan,jarak))
                                UDPSock.close()

                  else:
                                                   print "Gagal Login"
        else:
                print "User Tak Dikenali"  

# tutup socket
UDPSock.close()


sumber: http://www.mindtalk.com/ch/linux#!/post/4fe55317f7b73045ac001c64

0 comments:

Post a Comment

 

Copyright © BiruDaon Design by O Pregador | Blogger Theme by Blogger Template de luxo | Powered by Blogger