达到10的限制后,如何结束客户端服务器传输

时间:2018-09-16 00:55:27

标签: python sockets server client

我是网络新手,在传输十个字符串之后,需要一些帮助来完成传输。

这是我的服务器端

import socket           
import time 
from string import capitalize
from test.test_urllib2net import CloseSocketTest
from findertools import shutdown

host = "localhost" 
port = 3030
data = "just some text"
data = data.encode('utf-8')

s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)        

while 1:
  s.sendto(data,(host,port))
  print (capitalize("sent " + data.decode('utf-8')))
  time.sleep(1)

客户端

import socket
from server import host
from string import capitalize

HOST = "localhost"
PORT = 3030

t = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

t.bind((HOST,PORT))

while 1:
   print (t.recv(50))

0 个答案:

没有答案