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. Oracle个人自学笔记

    SET LINESIZE 300;//设置每一行的长度 SET PAGESIZE 100;//设置每一列的长度 CONN 用户名/密码 [AS SYSDBA],如果是sys用户一定要加上SYSDBA ...

  2. spring boot 是如何启动 tomcat

    Spring boot 的启动类启动后,tomcat 容器.Spring mvc .spring 事务等等第三方依赖也已经自动启动,那么spring boot 是如何启动的第三方依赖? 以spring ...

  3. FCN训练注意事项

    1.如果是类别受两类,需要把标签图二值化为0,1

  4. Linux centosVMware 负载均衡集群介绍、LVS介绍、LVS调度算法、LVS NAT模式搭建

    一.负载均衡集群介绍 主流开源软件LVS.keepalived.haproxy.nginx等 其中LVS属于4层(网络OSI 7层模型),nginx属于7层,haproxy既可以认为是4层,也可以当做 ...

  5. FTP的vsftpd.conf含义

    # 设置为YES时vsftpd以独立运行方式启动,设置为NO时以xinetd方式启动 #(xinetd是管理守护进程的,将服务集中管理,可以减少大量服务的资源消耗) listen=YES # 同上,如 ...

  6. 微信小程序测试request请求webapi

    using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Ne ...

  7. Codeforces 598D:Igor In the Museum

    D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. 关于AJAX跨域和原生AJAX CORS跨域解决

    项目需求要在别人的域名下调用自己的接口,因为浏览器的同源策略是不允许不同域名下之间的信息交换,那就意味着要跨域处理 参考博客 :https://blog.csdn.net/Ulricalin/arti ...

  9. vue 项目上传到码云,push时error: failed to push some refs to 'https://gitee.com/mawenrou/vue_ht.git'

    vue 项目上传到码云,push时error: failed to push some refs to 'https://gitee.com/mawenrou/vue_ht.git' 因为之前已经创建 ...

  10. bzoj 2111: [ZJOI2010]Perm 排列计数

    神题... 扒自某神犇题解: http://blog.csdn.net/aarongzk/article/details/50655471 #include<bits/stdc++.h> ...