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. 在abp core中出现运行项目时EF获取到的appsetting.json或者appsettings.Production.json中的连接字符串为空

    原因:有可能是生成的bin或者debug文件夹下没有将appsetting.json或者appsettings.Production.json文件生成过去 解决方法:手动拷贝过去,或者设置成自动生成过 ...

  2. 如何用一个servlet处理多个请求

    一个servlet处理多个请求,原理:利用反射机制获取在selvlet类中的其他方法1.前端页面<%@ page language="java" contentType=&q ...

  3. HDU 5564:Clarke and digits 收获颇多的矩阵快速幂 + 前缀和

    Clarke and digits  Accepts: 16  Submissions: 29  Time Limit: 5000/3000 MS (Java/Others)  Memory Limi ...

  4. web-pc项目中index页面分析

    先上HTML代码: <%@ page language="java" contentType="text/html; charset=UTF-8" pag ...

  5. bootloader与启动地址偏移

    如果项目工程是IAP+APP,则在keil的APP中要么在修改IROM/IRAM的开始地址和大小,并在MAP中勾选设置. 在NVIC中修改system_stm32f10x.c修改 这个在void Sy ...

  6. 调用百度汇率api 获取各国的汇率值

    设置一个定时任务,每天更新汇率java代码如下 package com.thinkgem.jeesite.modules.huiLvApi.service; import java.io.Buffer ...

  7. JS事件委托或者事件代理原理以及实现

    事件委托(事件代理)原理:简单的说就是将事件交由别人来执行,就是将子元素的事件通过冒泡的形式交由父元素来执行. 为什么要用时间委托? 在JavaScript中,添加到页面上的事件处理程序数量将直接关系 ...

  8. Scrapy 使用 LinkExtractor 提取链接和使用 Exporter 导出数据

    在爬取一个网站时,想要爬取的数据通常分布到多个页面中,每个页面包含一部分数据以及其他页面的链接,提取链接有使用 Selector 和使用 Linkextractor 两种方法. 1.使用Selecto ...

  9. vue v-model 数据双向绑定(笔记)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. lnmp一键安装的缺点???

    自己尝试几次在新的服务器上安装lnmp环境,每次都是一键安装,然后在/home/wwwroot/default目录下放对应的PHP文件就Ok了,很方便.其实也尝试过用命令行,就是很多命令的那种安装,中 ...