Chat Server

Iseng liat tutorial bikin chat server dan dengan client, masih simpel sih. Ngikutin video tutorial 😀

Special thanks, Ahmad Syarif 🙂 for his useful video

….dan seperti biasa, logika saya masih kelas melati. Rencananya dari sini mau dikembangkan lagi 😀

chat.PNG

server.py

import socket
import time

host = ‘0.0.0.0’
port = 4444

listenerSocket = socket.socket()
host = ‘0.0.0.0’
port = 4444
listenerSocket.bind((host, port))
listenerSocket.listen(0)

while True:
handlerSocket, addr = listenerSocket.accept()
print “Sebuah client telah terhubung dari ” ,addr
while True:
pesan = raw_input(“Masukan Pesan : “)
handlerSocket.send(pesan)
pesan = handlerSocket.recv(1024)
print ‘pesan dari klien :’ ,pesan
pass
pass

client.py

import socket

handlerSocket = socket.socket()
host = “127.0.0.1”
port = 4444

handlerSocket.connect((host,port))
print ‘terhubung’

while True:
pesan = handlerSocket.recv(1024)
print “Server :”,pesan
pesan = raw_input(“Client: “)
handlerSocket.send(pesan)
pass

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s