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 ...
随机推荐
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:设定文本小写
<!DOCTYPE html> <html> <head> <title>菜鸟教程(runoob.com)</title> <meta ...
- java 并发线程锁
1.同步和异步的区别和联系 异步,执行完函数或方法后,不必阻塞性地等待返回值或消息,只需要向系统委托一个异步过程,那么当系统接收到返回 值或消息时,系统会自动触发委托的异步过程,从而完成一个完整的流 ...
- Duilib XML嵌套/自定义控件
转载:https://www.jianshu.com/p/0fe8610dcc8d // https://github.com/Washington-DC/Duilib-ListView //这是 ...
- 「Luogu P2824 [HEOI2016/TJOI2016]排序」
一道十分神奇的线段树题,做法十分的有趣. 前置芝士 线段树:一个十分基础的数据结构,在这道题中起了至关重要的作用. 一种基于01串的神奇的二分思想:在模拟赛中出现了这道题,可以先去做一下,这样可能有助 ...
- SystemProperities
SystemProperties与Settings.System 1 使用 SystemProperties.get 如果属性名称以“ro.”开头,那么这个属性被视为只读属性.一旦设置,属性值不能改变 ...
- getline及读文件总结
今天由华为软件精英挑战赛的要求,读文件这块自己进行了总结,主要是泛型以及关联容器这块需要加强,现在总结了读文件的iterator的用法. 1.iterator inserter(essential C ...
- Using webpack-dev-server
官方讲解地址:https://webpack.js.org/guides/development/#using-webpack-dev-server The webpack-dev-server pr ...
- centos6.5安装图形操作界面
yum -y install xorg-x11-fonts-Type1 #安装Xwindow yum -y groupinstall "X Window System" #安装GN ...
- 《精通Objective-C》书籍目录
1.入门 2.使用类 3.对象和消息传递 4.内存管理 5.预处理器 6.专家级技巧:使用ARC 7.运行时系统 8.运行时系统的结构 9.专家级技巧:使用运行时系统API 10.Foundation ...
- 通过python 构建一个简单的聊天服务器
构建一个 Python 聊天服务器 一个简单的聊天服务器 现在您已经了解了 Python 中基本的网络 API:接下来可以在一个简单的应用程序中应用这些知识了.在本节中,将构建一个简单的聊天服务器.使 ...