Most simple basic of internet programming based on two different machines sharing the same local net
This blog is just shown for the most simple basic of internet programming based on two different machines sharing the same local net.While the client sends data to server, server just sends back data with timestamps
Server
(1)Parameter configure
import socket
from time import ctime
Host="" # host name,default to server machine's IP
Port=1300
addr=(Host,Port)
Bufsize=1024 # The maximum amount of data to be received at once is specified by bufsize
(2)Create server
Server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
AF-->address family,such as AF_LOCAL,AF_INET;SOCK_STREAM specifies using TCP,while SOCK_DGRAM specifies UDP.
Server.bind(addr)
Server.listen(5)
while True:
print('...Waiting to be connected...')
client,address=Server.accept() # default to be block mode,that is blocking while waiting. input() also has a flavor of block
while True:
data=client.recv(Bufsize)
if not data:
break
print(data)
client.send(bytes(ctime(),'utf8')+data)
client.close()
Server.close()
** In a summary**, server is just created as a socket object through socket.socket(),and then bind() this socket object with the machine, and then listen(), following that, going into
Client
Parameter config
import socket
Host='192.168.1.7'
Host number can be checked out by this: On the server machine,cmd-->ipconfig/all--->IPv4 address:192.168.1.7
Port=1300 # The same with server's port
Address=(Host,Port)
BufSize=1024
Create client
Client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
Client.connect(Address)
While True:
data=input('>>>')
if not data:
break
Client.send(bytes(data,'utf8'))
data=Client.recv(BufSize)
if not data:
break
print(data.decode('utf8'))
Client.close()
Most simple basic of internet programming based on two different machines sharing the same local net的更多相关文章
- hybrid programming based on python and C/C++
Python/C API Reference Manual¶ https://docs.python.org/3/c-api/index.html Extending and Embedding th ...
- net programming guid
Beej's Guide to Network Programming Using Internet Sockets Brian "Beej Jorgensen" Hallbeej ...
- 10 Questions To Make Programming Interviews Less Expensive--reference
Conducting Interview is not cheap and costs both time and money to a company. It take a lot of time ...
- Mercedes offline programming/coding tips and guides
Mercedes offline programming/coding recommendations and guides: Offline coding: SCN or CVN coding wa ...
- Comparison of programming paradigms
Main paradigm approaches[edit] The following are widely considered the main programming paradigms, a ...
- 00 what is C Programming?C编程是什么?
C语言简介 C is a programming language that lets us give a computer very specifio commands. C语言是一种编程语言,它让 ...
- Spring 3 Java Based Configuration with @Value
Springsource has released the Javaconfig Framework as a core component of Spring 3.0. There is a tre ...
- Book Review of "The Practice of Programming" (Ⅰ)
The Practice of Programming In the preface, the author illustrates four basic principles of programm ...
- (转) [it-ebooks]电子书列表
[it-ebooks]电子书列表 [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...
随机推荐
- minst.npz下载
keras.datasets.mnist数据集下载地址 下载地址:链接: https://pan.baidu.com/s/1Rr-aHsIIEQx2z6W3qvMmhQ 提取码: 8w15
- c#能同时继承接口和类吗
c#能同时继承接口和类吗?( 要你命3000条12级分类:C#/.NET语言被浏览449次2013.09.10 满意答案 mroyal450 采纳率:54%12级 2013.09.11 C# 类, ...
- Kubernetes 深入学习(一) —— 入门和集群安装部署
一.简介 1.Kubernetes 是什么 Kubernetes 是一个全新的基于容器技术的分布式架构解决方案,是 Google 开源的一个容器集群管理系统,Kubernetes 简称 K8S. Ku ...
- C# FileStream 对象的Seek()方法-----转载
原创 kevin617 发布于2010-12-08 11:22:00 阅读数 8630 收藏展开 FileStream 可以随机读写文件 使用 Seek 方法 Seek() ----------有两 ...
- rendering path定义了什么?有哪些?有什么作用?有什么限制?
rendering path 定义了光照在一个shader pass中处理的对象与顺序,如逐像素处理,逐顶点处理,向前处理,后向 deferred用于处理不透明物体,会先把它们根据深度检测,过滤后的内 ...
- 【剑指Offer面试编程题】题目1517:链表中倒数第k个结点--九度OJ
题目描述: 输入一个链表,输出该链表中倒数第k个结点. (hint: 请务必使用链表.) 输入: 输入可能包含多个测试样例,输入以EOF结束. 对于每个测试案例,输入的第一行为两个整数n和k(0< ...
- 【剑指Offer面试编程题】题目1386:旋转数组的最小数字--九度OJ
题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转 ...
- ubuntu16.04 使用tensorflow object detection训练自己的模型
一.构建自己的数据集 1.格式必须为jpg.jpeg或png. 2.在models/research/object_detection文件夹下创建images文件夹,在images文件夹下创建trai ...
- Calendar 时间类的应用
Date 类最主要的作用就是获得当前时间,同时这个类里面也具有设置时间以及一些其他的功能,但是由于本身设计的问题,这些方法却遭到众多批评,不建议使用,更推荐使用 Calendar 类进行时间和日期的处 ...
- VMware许可证过期解决方案
VMware 2017 v14.x 永久许可证激活密钥:FF31K-AHZD1-H8ETZ-8WWEZ-WUUVACV7T2-6WY5Q-48EWP-ZXY7X-QGUWD