Skip to content

Instantly share code, notes, and snippets.

@mike-zhang
mike-zhang / tcpClient1.py
Created September 29, 2012 09:20
a simple tcp client(python code)
#! /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 September 29, 2012 09:27
a simple udp client (python code)
#! /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 September 29, 2012 09:45
a simple tcp server (python code)
#! /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 September 29, 2012 09:48
a simple udp server (python code)
#! /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 October 8, 2012 15:33 — forked from wallrat/proxy.go
Simple GO TCP proxy
// 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 October 8, 2012 15:58
Implementation of a UDP proxy in Golang
// Implementation of a UDP proxy
package main
import (
"flag"
"fmt"
"log"
"net"
"os"
@mike-zhang
mike-zhang / httpShareWithTrace.go
Created October 10, 2012 14:25
http Share With Trace (golang)
/*
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 October 14, 2012 15:32
a simple udp proxy server (cpp code)
/*
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 October 15, 2012 06:36
定时显示特定网卡信息供查看
#! /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 October 18, 2012 08:08
STL find_if in member function
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
using namespace std;
class CMyTest
{
public:
bool IsOdd ( int i)