-
Notifications
You must be signed in to change notification settings - Fork 0
/
forwarding.py
31 lines (29 loc) · 919 Bytes
/
forwarding.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#tcp server
import socket
host = '127.0.0.1' #Local Server IP
host2 = '127.0.0.1' #Real Server IP
port = 8083 #Local Server Port
port2 = 7890 #Real Server Port
def ProcData(data):
return data
#add more code....
def run():
print ("Map Server start from " + host + ":" + str(port) +" to " + host2 + ":" + str(port2) +"\r\n")
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.bind((host,port))
print ("127.0.0.1 Server start at "+ str(port) +"\r\n")
client = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
client.connect((host2,port2))
print (host +" Client connect to " + host2 + ":"+str(port2)+"\n")
server.listen(5)
ss, addr = server.accept()
print ('got connected from',addr)
msg = ss.recv(20480)
print (msg)
client.send(msg)
buf=client.recv(20480)
ss.send(buf)
print(buf)
server.close
client.close
run()