36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
import os
|
|
import json
|
|
import random
|
|
import time
|
|
import threading
|
|
from tornado import ioloop
|
|
from tornado import gen
|
|
from tornado.websocket import websocket_connect
|
|
from tornado.tcpclient import TCPClient
|
|
|
|
class ClientSide:
|
|
|
|
def __init__(self, local_ip, remote_ip):
|
|
self._local_ip = local_ip
|
|
self._remote_ip = remote_ip
|
|
self.local_conn = None
|
|
self.remote_conn = None
|
|
|
|
@gen.coroutine
|
|
def co_connect(self):
|
|
while True:
|
|
if not self.local_conn:
|
|
[local_host, local_port] = self._local_ip.split(':')
|
|
local_conn = yield TCPClient().connect(local_host, local_port)
|
|
if not self.remote_conn:
|
|
[remote_host, remote_port] = self._remote_ip.split(':')
|
|
url = 'ws://%s:%s/websocket' % (remote_host, remote_port)
|
|
remote_conn = yield websocket_connect(url)
|
|
|
|
if self.local_conn:
|
|
pass
|
|
|
|
def run(self):
|
|
ioloop.IOLoop.current().run_sync(self.co_connect)
|