예제 #1
0
import socket
from fungsi import send_size, recv_size

# Inisiasi objek socket
tcp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Kirim permintaan koneksi ke server
tcp_sock.connect(("127.0.0.1", 6667))

# Kirim data
data = "Jurusan Sistem Informasi"
send_size(tcp_sock, data)

# Baca data yang dikirim balik oleh server
data = recv_size(tcp_sock)
print(data)

tcp_sock.close()
예제 #2
0
import socket
from fungsi import send_size, recv_size

# Inisiasi variabel socket
tcp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind ke IP dan port tertentu
tcp_sock.bind( ("0.0.0.0", 6667) )
# Listen 100 permintaan koneksi
tcp_sock.listen(100)

while True :
    # Terima permintaan koneksi dari client
    conn, client_addr = tcp_sock.accept()
    # Terima data dari client
    data = recv_size(conn)
    data = "OK "+data
    # Kirim balik ke client
    send_size(conn, data)
    # Tutup koneksi ke client
    #conn.close()
예제 #3
0
# import socket
import socket
from fungsi import send_size, recv_size

# Inisiasi socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Kirim permintaan koneksi ke alamat IP dan port server
sock.connect(("127.0.0.1", 7777))

# Kirim data ke server
#data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
data = "Ini Ibu Budi"
send_size(sock, data)
# Baca data
data = recv_size(sock)
print(data)