You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
المحاضرة الثانية: عمل server باستخدام بروتوكول UDP
اول شغله عندي لازم اعرف السوكيت يعني اعرف اساس الكونيكشن بالسيرفر على شنو يشتغل, socket.AF_INET معناها يشتغل على IPV4 و SOCK_DGRAM معناها يشتغل على UDP
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
import socket
# server settings
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
# set ip , and port
s.bind(("127.0.0.1",5555))
# set two variables, and set the buffer size for the variables
# 1024 bytes = 1 kilo byte
# why two variables ? recvfrom function return two data, one is the data the client sent which is Rdata, and the address will have the ip and port of the client
Rdata , address = s.recvfrom(1024)
# the data is coming encoded, so i net to decode the data
data = Rdata.decode("UTF-8") # UTF-8 or ascii ...
# Response from server to client
data_for_send = "Hello Client"
# Encode the data that need to send to client
Sdata = data_for_send,encoder("UTF-8")
# sendto function, send the data to client
s.sendto(Sdata,address)
المحاضرة الثالثة: برمجة client
import socket
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
data_for_send = " Hello Server "
Sdata = data_for_send.encode("UTF-8")
# sendto need two things, the data to be send, and the address
s.sendto(Sdata,("127.0.0.1",5555))
Rdata , address = s.recvfrom(1024)
data = Rdata.decode("UTF-8")
print("Data Recieved From {} : \n {} ".format(address,data))
datetime
اذا اريد اجيب الوقت الحالي, لازم استدعي مكتبة datetime
from datetime import datetime
time = str(datetime.now())
print time