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. Atcoder Beginner Contest 139E(模拟,思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int n;int a[1007][1007] ...

  2. 「Luogu P2824 [HEOI2016/TJOI2016]排序」

    一道十分神奇的线段树题,做法十分的有趣. 前置芝士 线段树:一个十分基础的数据结构,在这道题中起了至关重要的作用. 一种基于01串的神奇的二分思想:在模拟赛中出现了这道题,可以先去做一下,这样可能有助 ...

  3. js运算符的特殊应用

    是否包含指定字符: ~ 取整: | 取半: >> 成长值评级: || 判断奇偶: & 交换两个数字的值: ^= 2的n次方: << 和 ** 1 << n- ...

  4. java中内部类的实例化

  5. JavaScript图形实例:正多边形

    圆心位于坐标原点,半径为R的圆的参数方程为 X=R*COS(θ) Y=R*SIN(θ) 在圆上取N个等分点,将这N个点首尾连接N条边,可以得到一个正N边形. 1.正多边形阵列 构造一个8行8列的正N( ...

  6. Java单例模式:为什么我强烈推荐你用枚举来实现单例模式

    单例模式简介 单例模式是 Java 中最简单,也是最基础,最常用的设计模式之一.在运行期间,保证某个类只创建一个实例,保证一个类仅有一个实例,并提供一个访问它的全局访问点.下面就来讲讲Java中的N种 ...

  7. mybatis注解基础使用

      一.创建Maven项目 代码:pom.xml <?xml version="1.0" encoding="UTF-8"?> <projec ...

  8. 【剑指Offer面试编程题】题目1385:重建二叉树--九度OJ

    题目描述: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7 ...

  9. jmeter分布式linux负载机,windows主控机

    1.将参数化文件上传到linux服务器,放在linux上jmeter的bin路径下 2.设置server.rmi.ssl.disable=true 分别修改主控机和负载机的jmeter.propert ...

  10. MAC电脑如何播放.SWF文件

    很简单,不需要专门的播放器,只需要将.swf文件直接拖拽到浏览器页面就可以播放了. 亲测safari , 谷歌chrome浏览器,火狐浏览器 ,都是可以的 下面是图示 step1 电脑上找到swf文件 ...