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. 为什么需要NAT,目前家庭的计算机器如何上网?(原创)

    .什么是NAT?     字面翻译网络地址转换. 2.产生的背景    解决公网IP不足的问题.    官方规定,将IP地址资源进行分类,分为ABCDE,常用ABC三类,在每类中划分出了一些私有IP供 ...

  2. 如何批量删除.svn文件

    参考资料:https://www.cnblogs.com/kisf/articles/4760367.html 当项目不需要SVN标志的时候,我们一般怎么办哪??可能很多人设置Windows显示隐藏文 ...

  3. A - Bi-shoe and Phi-shoe 素数打表

    A - Bi-shoe and Phi-shoe Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi- ...

  4. CSS垂直居中的8种方法

    CSS垂直居中的8种方法 1.通过verticle-align:middle实现CSS垂直居中. 通过vertical-align:middle实现CSS垂直居中是最常使用的方法,但是有一点需要格外注 ...

  5. web前端面试第一次[addEventListenr();绑定事件]

    //当一个元素同时处理多个函数,这里使用按钮 //addEventListener(string类型,处理函数,boolean); <input type="button" ...

  6. 「luogu2633」Count on a tree

    「luogu2633」Count on a tree 传送门 树上主席树板子. 每个节点的根从其父节点更新得到,查询的时候差分一下就好了. 参考代码: #include <algorithm&g ...

  7. springboot,vue,shiro整合 关于登录认证功能

    首先是session问题 传统session认证 http协议是一种无状态协议,即浏览器发送请求到服务器,服务器是不知道这个请求是哪个用户发来的.为了让服务器知道请求是哪个用户发来的,需要让用户提供用 ...

  8. Java8使用Stream优雅地处理集合

    说明 集合和数组是我们经常会用到的数据结构,在jdk1.8之前,集合和数组的处理并不是很便捷.但是到了JDK1.8之后,使用Stream处理集合会使代码变得更加的简洁明了.作为一名开发者,其实很有必要 ...

  9. JMeter配置JDBC测试SQL Server/MySQL/ORACLE

    一.配置SQL Server 1.下载sql驱动,将sqljdbc4.jar放到JMeter安装目录/lib下. 2.启动JMeter,右键添加->配置文件->JDBC Connectio ...

  10. 九 SpringMvc与json交互

    将json输出到页面: 1 加入jar包 2 配置Controller层,开启注解ResponseBody,将json发送到页面: 3 访问url 4 响应json,在形参列表里面加上注解