zoukankan      html  css  js  c++  java
  • python udp客户端与服务端交互

    服务端:

     1 from socket import *
     2 import re
     3 
     4 
     5 udp_socket=socket(AF_INET,SOCK_DGRAM)
     6 udp_socket.bind(('0.0.0.0',8848))
     7 csin=True
     8 while True:
     9     data,addr=udp_socket.recvfrom(1024)
    10     if data.decode()=='1':
    11         print("客户关闭程序")
    12     else:
    13         rade = open('dict.txt')
    14         for i in rade:
    15             word=re.findall(r'(w+)s+(.*)',i)
    16             print(word)
    17             if word[0][0]==data.decode():
    18                 print(word)
    19                 print(word[0][0])
    20                 print(word[0][0]==data.decode())
    21                 udp_socket.sendto(word[0][1].encode(), addr)
    22 
    23 udp_socket.close()

    客户端:

     1 from  socket import *
     2 
     3 
     4 
     5 udp_socket=socket(AF_INET,SOCK_DGRAM)
     6 
     7 # text="我进来了,我又出去了,我又进来了,你打我呀,打我呀,笨蛋.".encode()
     8 csin=True
     9 while csin:
    10     text=input("客户('1'.退出)>>")
    11     if text=='1':
    12         udp_socket.sendto(text.encode(),('127.0.0.1',8848))
    13         csin=False
    14     else:
    15         udp_socket.sendto(text.encode(),('127.0.0.1',8848))
    16     data,addr=udp_socket.recvfrom(1024)
    17     print(data.decode())
    18 udp_socket.close()
    客户端

    服务端处理的内容

    a                indef art one

    abacus           n.frame with beads that slide along parallel rods, used for teaching numbers to children, and (in some countries) for counting

    abandon          v.  go away from (a person or thing or place) not intending to return; forsake; desert

    abandonment      n.  abandoning

    abase            v. ~ oneself/sb lower oneself/sb in dignity; degrade oneself/sb ;

    abash            to destroy the self-possession or self-confidence of:disconcert

    abashed          adj. ~ embarrassed; ashamed

    abate            v. make or become less

    abattoir         n. = slaughterhouse (slaughter)

    abbess           n. woman who is head of a convent or nunnery

    abbey            n.  buildingin which monks or nuns live as a community under an abbot or abbess

    abbot            n. man who is head of a monastery or abbey

    abbreviate       v. ~ sth shorten (a word, phrase, etc), esp by omitting letters

    abbreviation     n.  abbreviating or being abbreviated

    abdicate         v.  resign from or formally renounce the throne

    abdication       giving up control, authority

    abdomen          n.  part of the body below the chest and diaphragm, containing the stomach, bowels and digestive organs

    abdominal        adj. in, of or for the abdomen

    abduct           v. take away illegally, using force or deception; kidnap ;

    abduction        A carrying away of a person against his will, or illegally.

    abed             In bed; on a bed.

    aberrant         adj. not following the normal or correct way

    aberration       n.  deviation from what is accepted as normal or right

    abet             v.  ~ sb (in sth) help or encourage sb to commit an offence or

    2020-07-08

    from  socket import *



    udp_socket=socket(AF_INET,SOCK_DGRAM)

    # text="我进来了,我又出去了,我又进来了,你打我呀,打我呀,笨蛋.".encode()
    csin=True
    while csin:
    text=input("客户('1'.退出)>>")
    if text=='1':
    udp_socket.sendto(text.encode(),('127.0.0.1',8848))
    csin=False
    else:
    udp_socket.sendto(text.encode(),('127.0.0.1',8848))
    data,addr=udp_socket.recvfrom(1024)
    print(data.decode())
    udp_socket.close()
  • 相关阅读:
    新年第一个项目思考
    ICP通讯(EN)
    将绝对路径变成URL路径(原创)
    [图像处理] 铁路轨道道岔检测(一)
    一个外国的好网站 http://www.ilovejackdaniels.com/
    内容全面的企业网站策划书
    asp.net2.0学习历程 菜鸟到中级程序员的飞跃
    TimeSpan 用法 求离最近发表时间的函数
    ASP.NE导出Excel
    在网页中,鼠标放在Flash链接上,光标形状会在手型和鼠标之间不停的闪 的解决办法
  • 原文地址:https://www.cnblogs.com/yongqi-wang/p/13269120.html
Copyright © 2011-2022 走看看