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的更多相关文章

  1. 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 ...

  2. net programming guid

    Beej's Guide to Network Programming Using Internet Sockets Brian "Beej Jorgensen" Hallbeej ...

  3. 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 ...

  4. Mercedes offline programming/coding tips and guides

    Mercedes offline programming/coding recommendations and guides: Offline coding: SCN or CVN coding wa ...

  5. Comparison of programming paradigms

    Main paradigm approaches[edit] The following are widely considered the main programming paradigms, a ...

  6. 00 what is C Programming?C编程是什么?

    C语言简介 C is a programming language that lets us give a computer very specifio commands. C语言是一种编程语言,它让 ...

  7. 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 ...

  8. Book Review of "The Practice of Programming" (Ⅰ)

    The Practice of Programming In the preface, the author illustrates four basic principles of programm ...

  9. (转) [it-ebooks]电子书列表

    [it-ebooks]电子书列表   [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...

随机推荐

  1. java面试题蚂蚁

    hashmap结构:什么对象能做为key hashtable,concurrentHashMap,hashtable比较 String,StringBuilder,StringBuffer 对象的深浅 ...

  2. redhat 7.6 find 命令

    1.按名字查找 find  ./    -name  filename    //精确查找 ,./ 代表当前目录   -name 查询名称 filename具体文件名称 find  ./    -na ...

  3. Mac brew安装的php修改了php.ini之后如何重启php?

    环境:nginx+mysql+php7.2:Mac利用homebrew安装的php7.2 问题:修改了PHP的配置文件,php.ini:服务器是nginx,如何重启PHP? 开启: brew serv ...

  4. 隧道技术(Tunneling)

    隧道技术及其应用 隧道技术(Tunneling)是一种通过使用互联网络的基础设施在网络之间传递数据的方式.使用隧道传递的数据(或负载)可以是不同协议的数据帧或包.隧道协议将其它协议的数据帧或包重新封装 ...

  5. MySQL帮助文档的使用

    帮助文档使用 在 MySQL 使用过程中,可能经常会遇到以下问题: 某个操作语法忘记了,需要快速查找. 当前版本上,某个字段类型我们想快速知道它的取值范围? 当前版本上,都支持哪些函数?希望有例子能快 ...

  6. 浅谈Windows入侵检查

    1 准备工作   检查人员应该可以物理接触可疑的系统.因为黑客可能侦测到你可以在检查系统,例如网络监听,所以物理接触会比远程控制更好. 为了当做法庭证据可能需要将硬盘做实体备份.如果需要,断开所有与可 ...

  7. web应用基础架构

    1.web中间件 中间件是一类连接软件组件和应用的计算机软件,它包括一组服务.以便运行在一台或多台服务器上的多个软件通过网络进行交互.该技术所提供的互操作性,推动了一致分布式体系架构的演进,该架构通常 ...

  8. springboot,dubbo,nacos,spring-cloud-alibaba的整合

    最近,自去年阿里开源了dubbo2.7及一系列产品后,阿里也打造了融入spring-cloud 的生态体系,本人关注,今年阿里开源的的spring-cloud-alibaba基本孵化完成,笔者更是对这 ...

  9. Java面向对象之类、接口、多态

    Java面向对象之类.接口.多态 类 class Person { // 实例属性 int age; String name; // 类属性 static int v = 1; // 构造器 publ ...

  10. 「CF5E」Bindian Signalizing

    传送门 Luogu 解题思路 很显然的一点,任何一条可能成为路径的圆弧都不可能经过最高的点,除非这条路径全是最高点. 所以我们先把最大值抠掉,把剩下的按原来的顺序排好. 从前往后.从后往前扫两次,用单 ...