- 博客(13)
- 资源 (4)
- 收藏
- 关注
原创 通过设置套接字阻塞与非阻塞使UDP 接收到的数据始终为最新的数据
代码:#include"common.h"int fd;int abc = 1000;struct sockaddr_in caddr;int addr_len;static void setnonblocking(int sockfd) { //设置阻塞 int flag = fcntl(sockfd, F_GETFL, 0); if (flag...
2019-01-18 17:38:21 816
原创 python 6.0 TCP
#! /usr/bin/python3.4from socket import *from time import ctimeimport selectimport queuefrom time import sleephost = '127.0.0.1'port = 8888buffsize = 2048ADDR = (host,port)server = socke...
2019-01-16 20:41:50 247
原创 共享内存 3.0 进程锁 与 进程锁
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <wait.h>#include <fcntl.h>#include <str...
2019-01-16 17:48:20 388
原创 python 5.0 正则表达式
#! /usr/bin/python3.4import res = "abc def ghi"s = re.split("\s*",s) # \s*表示匹配所有空格,包括制表符(多次,比如两个空格相连)print(s) # ['abc', 'def', 'ghi'] s = "abc,def;ghi" # 匹配','或者';'s = re.split(",|;",s)# ...
2019-01-15 19:44:09 306
原创 Python 4.0 引用与复制
所有对象都有引用计数#! /usr/bin/python3.4import sysa = 37 # 创建一个值为37的对象,a引用这个对象的一个名称count = sys.getrefcount(a) # 获得对象的当前引用计数print(count) # 9b=a #增加37的引用计数c=a #增加37的引用计数print(sys.getrefco...
2019-01-08 19:53:22 247 1
原创 Python 3.0 yield 生成器与协程
使用yield语句(任何使用yield的函数都称为生成器,不用return进行返回),可以让函数生成一个结果序列,而不仅仅是返回一个值,生成器会分步执行,如果使用next()调用生成器,每次都会执行到下一条yield语句为止。#! /usr/bin/python3.4def countdown(n): print ("Counting down!") print (n,"\n") ...
2019-01-08 17:24:10 183
原创 Python 2.0 列表、元组、字典、集合
1、列表列表是任意对象的序列(用[ ]):#! /usr/bin/python3.4values = [200,100,400,100]values.append(500) # 添加在末尾print("values[4]=" + "%d" % (values[4])) # 500values.insert(2,300) # 添加到第几个对象的后面...
2019-01-08 14:22:46 194
原创 Python 1.0 文件操作
此文档包括之后的Python只适用于Python3f = open("./123.txt","w")a=3while(a>0): if(a==3): print("%s" % ("aaa"),file=f) if(a==2): print("%s" % ("111"),file=f) if(a==1): print("%s" %
2019-01-08 11:29:12 183
原创 JAVA 3.0 ------- 集合容器
package notebook;import java.util.HashSet;public class NoteBook{ public static void main(String[] args){ HashSet<String> s =new HashSet<String>(); s.add("first"); s.add("sec...
2019-01-04 13:58:41 133
原创 JAVA 3.0 对象数组
package notebook;public class NoteBook{ public static void main(String[] args){ int [] ia = new int[10]; String[] a = new String[10]; ia[2]=ia[2]+10; System.out.println(ia[2]); ...
2019-01-03 20:40:31 133
原创 JAVA 3.0 容器 ----顺序容器
package notebook;import java.util.ArrayList;public class NoteBook { private ArrayList<String>notes = new ArrayList<String>(); private int size = 0; /*添加元素*/ public void add(Str...
2019-01-03 19:21:17 314
原创 JAVA 2.0 时钟
时、秒 类:public class Display { private int value = 0; private int limit = 0; Display(int limit) { this.limit=limit; } void increase() { value++; if(value == limit) { value = 0;...
2019-01-03 15:44:15 235
原创 JAVA 1.0 -------- VendingMachine 售货机
public class VendingMachine { int price=80; int balance; int total; //函数重载:--------------------------------------- VendingMachine(int total) //构造函数 { this.total = total; } VendingMach...
2019-01-03 15:27:25 617
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人