小编Cho*_*rin的帖子

如何在python中创建一个简单的代理?

我想用python创建一个非常简单的代理(主要是为了理解它是如何工作的).我在谈论一个通用的TCP代理,而不仅仅是http.我已经构建了以下代码,但是,它似乎只能以一种方式工作:即请求已发送但我从未得到答案.这是代码:

import socket
import argparse

#Args
parser = argparse.ArgumentParser(description='ProxyDescription')
parser.add_argument('-l', '--listen', action='store', help='Listening port', default=80, type=int)
parser.add_argument('destination', action='store', help='Destination host')
parser.add_argument('port', action='store', help='Destination port', type=int)
args = parser.parse_args()

#Server
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.bind(('', args.listen))
s1.listen(1)
conn1, addr1 = s1.accept()

#Client
s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2.connect((args.destination, args.port))
s2.setblocking(0)

print "Connected by ", addr1
while 1:
    datato = conn1.recv(1024)
    if not datato: 
        print "breaking to"
        break
    s2.send(datato)
    print "data send : " + datato
    try:
        datafrom = s2.recv(1024)
        print "reveived data …
Run Code Online (Sandbox Code Playgroud)

python sockets proxy

7
推荐指数
1
解决办法
2万
查看次数

如何专门化模板化类的成员结构

说我有以下模板化的类:

template<typename T>
class Foo {
    struct store_t {
        uint8_t data[];
    } store;
    /// other stuff using T
}
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以构造内部结构的专用版本,该版本等同于以下内容:

class Foo {
    struct store_t {
        uint16_t f1;
        uint16_t f2;
    } store;
    /// other stuff using T
}
Run Code Online (Sandbox Code Playgroud)

I would prefer to keep most of the "other stuff using T" unspecialized. I would specialize some accessors though. I feel I would want to write something like

template<>
struct store_t {
    uint16_t f1;
    uint16_t f2;
} Foo<someT>::store;
Run Code Online (Sandbox Code Playgroud)

but that of course …

c++ templates template-specialization

4
推荐指数
1
解决办法
83
查看次数