Skip to content

Instantly share code, notes, and snippets.

@mike-zhang
mike-zhang / tcpClient1.py
Created Sep 29, 2012
a simple tcp client(python code)
View tcpClient1.py
#! /usr/bin/python
# a simple tcp client
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('127.0.0.1', 12345))
#sock.send('Test\n')
sock.send(raw_input("Please input : "))
print sock.recv(1024)
sock.close()
@mike-zhang
mike-zhang / udpClient1.py
Created Sep 29, 2012
a simple udp client (python code)
View udpClient1.py
#! /usr/bin/python
# a simple udp client
import socket,time,traceback
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dstHost = ('192.168.1.100', 12345)
while True:
try:
client.sendto('3',dstHost)
print time.time(),' : send success'
@mike-zhang
mike-zhang / tcpServer1.py
Created Sep 29, 2012
a simple tcp server (python code)
View tcpServer1.py
#! /usr/bin/python
# a simple tcp server
import socket,os
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('127.0.0.1', 12345))
sock.listen(5)
while True:
connection,address = sock.accept()
buf = connection.recv(1024)
print buf
@mike-zhang
mike-zhang / udpServer1.py
Created Sep 29, 2012
a simple udp server (python code)
View udpServer1.py
#! /usr/bin/python
# a simple udp server
import socket, traceback
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("127.0.0.1",12345))
while 1:
try:
@mike-zhang
mike-zhang / netfwd.go
Created Oct 8, 2012 — forked from wallrat/proxy.go
Simple GO TCP proxy
View netfwd.go
// can be run in go 1.0.3
// build : go build netfwd.go
package main
import (
"net"
"fmt"
"io"
"os"
)
@mike-zhang
mike-zhang / udpProxy.go
Created Oct 8, 2012
Implementation of a UDP proxy in Golang
View udpProxy.go
// Implementation of a UDP proxy
package main
import (
"flag"
"fmt"
"log"
"net"
"os"
@mike-zhang
mike-zhang / httpShareWithTrace.go
Created Oct 10, 2012
http Share With Trace (golang)
View httpShareWithTrace.go
/*
File : httpShareWithTrace.go
Author : Mike
E-Mail : Mike_Zhang@live.com
*/
package main
import (
"net/http"
"os"
"strings"
@mike-zhang
mike-zhang / udpProxyServer.cpp
Created Oct 14, 2012
a simple udp proxy server (cpp code)
View udpProxyServer.cpp
/*
File : udpProxyServer.cpp
Author : Mike
E-Mail : Mike_Zhang@live.com
*/
#include <cstdlib>
#include <cstddef>
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
@mike-zhang
mike-zhang / watch_eth0.sh
Created Oct 15, 2012
定时显示特定网卡信息供查看
View watch_eth0.sh
#! /bin/sh
if [ -f '/usr/bin/watch' ]
then
watch -n 1 -d ifconfig eth0
#watch ifconfig eth0
else
#while [ 1 ];do ifconfig eth0 ;sleep 1;clear;done
while [ 1 ]
do
@mike-zhang
mike-zhang / find_if_inMemeberFun.cpp
Created Oct 18, 2012
STL find_if in member function
View find_if_inMemeberFun.cpp
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
using namespace std;
class CMyTest
{
public:
bool IsOdd ( int i)