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 ...
随机推荐
- C++ 知识零碎搭建
全局变量 局部变量 函数不能嵌套定义 C/C++ 变量在将要被使用时定义即可, 不必一开始就声明所有变量 函数的定义与声明的区别 C++常规类型自动类型转换规则 C语言中十六进制和八进制的格式: 二进 ...
- spring boot 中容器 Jetty、Tomcat、Undertow
spring boot 中依赖tomcat <dependency> <groupId>org.springframework.boot</groupId> < ...
- 让eclipse恢复默认布局
参考:https://blog.csdn.net/howlaa/article/details/39178359 Window -> Perspective -> Reset Perspe ...
- vs2013中配置SQLite数据库
转载:https://maplefan.com/index.php/2019/08/14/visual-studio-2013%e9%85%8d%e7%bd%aesqlite3%e7%9a%84%e6 ...
- redhat 7.6 VI编辑操作
模式一: 浏览模式 0 : 光标到行首 $ : 光标到行尾 gg:光标到首行 G:光标到尾行 yy:复制光标所在行 dd:剪切光标所在行,删除行 y11y:复制光标所在行,往下数,一共10行 p:粘贴 ...
- Django学习 之 HTTP与WEB为Django做准备
一.HTTP 1.HTTP 简介 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是因特网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标准. ...
- 116、Java中String类之大小写转换
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- 设计模式---JDK动态代理和CGLIB代理
Cglig代理设计模式 /*测试类*/ package cglibProxy; import org.junit.Test; public class TestCglib { @Test public ...
- github 创建分支
1.github网站创建 参考:https://www.cnblogs.com/autoXingJY/p/9004724.html 2.命令更新 参考:https://www.cnblogs.com/ ...
- [Hello 2020] C. New Year and Permutation (组合数学)
[Hello 2020] C. New Year and Permutation (组合数学) C. New Year and Permutation time limit per test 1 se ...