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 ...
随机推荐
- Java基础 -2.4
字符型char类型 在任何的编程语言之中,字符都可以与int进行互相转换,也就是这个字符中所描述的内容可以通过int获取其内容所在的系统编码 public class ddd { public sta ...
- for循环语句及批量创建用户!
1.for 语句结构for 变量名 in 取值列表do命令序列done ================================================================ ...
- python基本输入输出函数与变量类型
7.python具有三个重要的输出输入函数:print(输出)/eval(转换)/input(输入): 8.对于输出函数print函数的具体使用规则如下:(1)输出字符串:print("字符 ...
- Linux系统chmod命令的含义和权限详解
许多喜欢使用chmod命令的用户,对chmod命令的含义和权限仍然不是很清楚,因此在使用的时候对它们造成了一定的麻烦.为了解决这些用户的迷惑,今天小编就和大家一起分享下chmod命令的含义和权限. 对 ...
- 线程context
线程切换的时候,要保存当前运行状态,以便后续切换回来 CONTEXT结构体保存的是一堆寄存器 两个函数 //You cannot get a valid context for a running t ...
- POJ 1166:The Clocks
The Clocks Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15357 Accepted: 6230 Descr ...
- day11-Python运维开发基础(迭代器与可迭代对象、高阶函数)
1. 迭代器与可迭代对象 # ### 迭代器 """ 迭代器: 能被next方法调用,并且不断返回下一个值的对象,是迭代器(对象) 特征:迭代器会生成惰性序列,它通过计算 ...
- 二、多线程基础-乐观锁_悲观锁_重入锁_读写锁_CAS无锁机制_自旋锁
1.10乐观锁_悲观锁_重入锁_读写锁_CAS无锁机制_自旋锁1)乐观锁:就像它的名字一样,对于并发间操作产生的线程安全问题持乐观状态,乐观锁认为竞争不总是会发生,因此它不需要持有锁,将 比较-设置 ...
- jquery源码部分分析
1.整体架构和如何辨别浏览器端和node端 自执行函数,判断在什么端,如果在浏览器端就执行factory函数 //(function(){a,b})(a,b) //jq大架构,闭包,自执行函数,传入函 ...
- 080、Java数组之二维数组的定义及使用
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...