2014년 5월 14일 수요일
2014년 5월 13일 화요일
SocketServer, select 이용 tcp relay 파이썬 간단 구현
아래 링크를 참조하여 tcp relay 하는 코드 작성.
http://code.activestate.com/recipes/114642/
http://pymotw.com/2/select/
http://code.activestate.com/recipes/114642/
http://pymotw.com/2/select/
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# std
import Queue
import select
import socket
import SocketServer
#-------------------------------------------------------------------------------
class TCPRelayPair(object):
def __init__(self, pair_sock):
self.pair_sock = pair_sock
self.queue = Queue.Queue()
#-------------------------------------------------------------------------------
class TCPRelayHandler(SocketServer.StreamRequestHandler):
def handle(self):
print "connected: %s" % (self.client_address,)
self.request.setblocking(0)
fwd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
fwd.connect(("localhost", 8080))
fwd.setblocking(0)
pair_map = {
self.request: TCPRelayPair(fwd),
fwd: TCPRelayPair(self.request)
}
rlist = pair_map.keys()
wlist = []
while 1:
readable, writable, exceptional = select.select(rlist, wlist, rlist)
disconnected = False
for sock in readable:
rdat = sock.recv(4096)
if rdat:
#print "rdat=", rdat
pair_sock = pair_map[sock].pair_sock
pair_map[pair_sock].queue.put(rdat)
if pair_sock not in wlist:
wlist.append(pair_sock)
else:
disconnected = True
for sock in writable:
try:
wdat = pair_map[sock].queue.get_nowait()
except Queue.Empty:
#print "write queue empty"
wlist.remove(sock)
else:
#print "wdat=", wdat
sock.sendall(wdat)
if disconnected or exceptional:
break
finally:
fwd.close()
print "disconnected: %s" % (self.client_address,)
#-------------------------------------------------------------------------------
def run_relay_server():
relay_svr = SocketServer.ThreadingTCPServer(('', 9090), TCPRelayHandler)
relay_svr.serve_forever()
#-------------------------------------------------------------------------------
def main():
run_relay_server()
#-------------------------------------------------------------------------------
if __name__ == "__main__":
main()
2014년 5월 6일 화요일
2013년 12월 8일 일요일
CentOS, "Multilib version problems found. This often means that the root" 에러.
https://bugzilla.redhat.com/show_bug.cgi?id=861169
어느 패키지가 충돌나는지 알 수 있음.yum check yum distro-sync
2013년 12월 4일 수요일
subversion 저장소 동기화(백업)
- 클라이언트 PC 에 동기화 레포지토리 생성.
D:\prj>svnadmin create myrepo
- hooks 폴더 밑에 다음과 같은 파일 생성.
- 윈도 : pre-revprop-change.bat, 내용없는 빈 파일.
- 리눅스
- 다음 내용을 갖는 pre-revprop-change 파일 생성.
#!sh
- 실행권한 변경.
chmod 777 pre-revprop-change
- 다음 내용을 갖는 pre-revprop-change 파일 생성.
- 레포지토리 초기화
D:\prj>svnsync init file:///d:/prj/myrepo svn://192.168.123.210/myrepo - 레포지토리 동기화
D:\prj>svnsync sync file:///d:/prj/myrepo - 이후로는 레포지토리 동기화 명령만 수행하면 계속 동기화 될 듯 함.
2012년 12월 9일 일요일
2012년 12월 2일 일요일
ctypeslib 를 mingw 와 같이 쓰기.
2008년도에 파이썬마을 강좌란(http://python.kr/viewtopic.php?t=23655) 써 놓은 글인데 한동안 파이썬마을이 불안정했던 적이 있어서 백업차원에서 여기에 다시 정리.
----------------------------------------------------------
윈도환경에서 ctypes 를 가끔 쓰고 있는데 WIN32 API 를 일일히 기술하려니 짜증~~
그래서, ctypes 홈페이지를 보니 역시 ctypeslib 라는 자동화툴이 있더군요.
문제는 ctypes 홈페이지에 있는 gccxml 윈도용 설치파일이 mingw(정확히는 g++)를 지원하지 않습니다.
CVS 에 있는 gccxml 은 mingw 를 지원하는데 윈도용 설치파일은 따로 없더군요.
그래서, 삽질을 시작했습니다.
0. 작업환경
Windows 7 SP1 64bit, Python 2.7.3 32bit
1. mingw 설치하기.
gccxml 빌드시, ctypeslib 사용시에 mingw 가 필요함.
mingw(http://www.mingw.org/) 또는 tdm-gcc(http://tdm-gcc.tdragon.net/) 설치.
여기서는 tdm-gcc 사용.
PATH 환경변수에 mingw 의 bin 폴더를 추가함.
2. CMake 설치.
cmake(http://www.cmake.org/) 를 설치.
PATH 환경변수에 cmake 의 bin 폴더를 추가.
3. gccxml 소스 체크아웃.
http://gccxml.org/HTML/Index.html 를 참고하여 gccxml 소스 체크아웃함.
(여기서는 d:\prj\gccxml\gccmxl 에 체크아웃)
4. CMake 로 gccxml 빌드환경 설정.
cmake-gui.exe 실행.
Where is the source code : 소스폴더지정(여기서는 d:\prj\gccxml\gccxml)
Where is the binaries : 빌드된 바이너리 저장폴더 지정.(여기서는 d:\prj\gccxml\build 폴더 만들고 지정)
Configure 버튼 누름.
Mingw Makefiles 항목 선택.
정상적으로 되었으면 CMAKE_BUILD_TYPE, CMAKE_INSTALL_PREFIX 항목 보임.
CMAKE_BUILD_TYPE 항목 : Release 라고 타이핑.
CMAKE_INSTALL_PREFIX : 어떤 항목인지 모름. 여기서는 c:\devtool\gccxml 폴더 만들고 지정. (최종적으로 여기에 설치됨)
다시, Configure 버튼 누름.
Generate 버튼 누름.
5. gccxml 빌드
명령행에서 build 폴더( 여기서는 d:\prj\gccxml\build ) 로 이동
mingw32-make 실행.
mingw32-make install 실행.
정상적이면 빌드폴더의 bin 폴더( 여기서는 c:\devtool\gccxml\build\bin ) 에 gccxml.exe 생성됨.
bin 폴더를 PATH 환경변수에 추가함.
(주의 : mingw\bin 폴더가 gccxml\bin 폴더보다 앞에 있어야 함
즉. set PATH=c:\devtool\mingw\bin;c:\devtool\gccxml\bin;%PATH% )
GCCXML_COMPILER 환경변수를 새로 만들고 g++ 이라고 입력함.
(만약, msvc를 사용할려면 msvc6,msvc7,msvc9.. 등으로 설정. 테스트해보지 않음
자세한 것은 doc 폴더(여기서는 c:\devtool\gccxml\build\GCC_XML\doc) 문서 참조.)
6. ctypeslib 체크아웃 및 설치.
ctypeslib(http://pypi.python.org/pypi/ctypeslib 또는 http://starship.python.net/crew/theller/ctypes/)에서 소스를 체크아웃후 설치.
7. ctypeslib 사용
ctypeslib 문서를 참조하여 다음과 같은 파이썬 코드 실행.
----------------------------------------------------------
윈도환경에서 ctypes 를 가끔 쓰고 있는데 WIN32 API 를 일일히 기술하려니 짜증~~
그래서, ctypes 홈페이지를 보니 역시 ctypeslib 라는 자동화툴이 있더군요.
문제는 ctypes 홈페이지에 있는 gccxml 윈도용 설치파일이 mingw(정확히는 g++)를 지원하지 않습니다.
CVS 에 있는 gccxml 은 mingw 를 지원하는데 윈도용 설치파일은 따로 없더군요.
그래서, 삽질을 시작했습니다.
0. 작업환경
Windows 7 SP1 64bit, Python 2.7.3 32bit
1. mingw 설치하기.
gccxml 빌드시, ctypeslib 사용시에 mingw 가 필요함.
mingw(http://www.mingw.org/) 또는 tdm-gcc(http://tdm-gcc.tdragon.net/) 설치.
여기서는 tdm-gcc 사용.
PATH 환경변수에 mingw 의 bin 폴더를 추가함.
2. CMake 설치.
cmake(http://www.cmake.org/) 를 설치.
PATH 환경변수에 cmake 의 bin 폴더를 추가.
3. gccxml 소스 체크아웃.
http://gccxml.org/HTML/Index.html 를 참고하여 gccxml 소스 체크아웃함.
(여기서는 d:\prj\gccxml\gccmxl 에 체크아웃)
| D:\prj\gccxml\gccxml>dir
D 드라이브의 볼륨: 새 볼륨 볼륨 일련 번호: 7C0A-AD6D D:\prj\gccxml\gccxml 디렉터리 2008-03-19 19:47 (DIR) . 2008-03-19 19:47 (DIR) .. 2008-02-15 09:50 1,114 CMakeLists.txt 2008-03-19 19:47 (DIR) GCC 2007-11-01 00:57 2,688 gccxmlCPack.cmake 2008-03-19 19:47 (DIR) GCC_XML 2007-11-29 04:52 2,312 README 3개 파일 6,114 바이트 4개 디렉터리 66,559,102,976 바이트 남음 D:\prj\gccxml\gccxml> |
4. CMake 로 gccxml 빌드환경 설정.
cmake-gui.exe 실행.
Where is the source code : 소스폴더지정(여기서는 d:\prj\gccxml\gccxml)
Where is the binaries : 빌드된 바이너리 저장폴더 지정.(여기서는 d:\prj\gccxml\build 폴더 만들고 지정)
Configure 버튼 누름.
Mingw Makefiles 항목 선택.
정상적으로 되었으면 CMAKE_BUILD_TYPE, CMAKE_INSTALL_PREFIX 항목 보임.
CMAKE_BUILD_TYPE 항목 : Release 라고 타이핑.
CMAKE_INSTALL_PREFIX : 어떤 항목인지 모름. 여기서는 c:\devtool\gccxml 폴더 만들고 지정. (최종적으로 여기에 설치됨)
다시, Configure 버튼 누름.
Generate 버튼 누름.
5. gccxml 빌드
명령행에서 build 폴더( 여기서는 d:\prj\gccxml\build ) 로 이동
mingw32-make 실행.
mingw32-make install 실행.
정상적이면 빌드폴더의 bin 폴더( 여기서는 c:\devtool\gccxml\build\bin ) 에 gccxml.exe 생성됨.
bin 폴더를 PATH 환경변수에 추가함.
(주의 : mingw\bin 폴더가 gccxml\bin 폴더보다 앞에 있어야 함
즉. set PATH=c:\devtool\mingw\bin;c:\devtool\gccxml\bin;%PATH% )
GCCXML_COMPILER 환경변수를 새로 만들고 g++ 이라고 입력함.
(만약, msvc를 사용할려면 msvc6,msvc7,msvc9.. 등으로 설정. 테스트해보지 않음
자세한 것은 doc 폴더(여기서는 c:\devtool\gccxml\build\GCC_XML\doc) 문서 참조.)
6. ctypeslib 체크아웃 및 설치.
ctypeslib(http://pypi.python.org/pypi/ctypeslib 또는 http://starship.python.net/crew/theller/ctypes/)에서 소스를 체크아웃후 설치.
7. ctypeslib 사용
ctypeslib 문서를 참조하여 다음과 같은 파이썬 코드 실행.
피드 구독하기:
글 (Atom)