def proxy(conn, host, portout):

    conn2 = jsockets.socket_tcp_connect(host, portout)
    if conn2 is None:
        print('conexión rechazada por ' + host + ', ' + portout)
        sys.exit(1)

    print('Cliente conectado')

    newthread1 = threading.Thread(target=Rdr, daemon=True, args=(conn, conn2))
    newthread1.start()
    Rdr(conn2, conn)
    print('Cliente desconectado')
Esempio n. 2
0
def proxy(conn, addr, data, host, portout):

    conn2 = jsockets.socket_tcp_connect(host, portout)
    if conn2 is None:
        print('conexión rechazada por ' + host + ', ' + portout)
        sys.exit(1)

    conn.connect(addr)
    # timeout de 100s, para que muera sin tráfico
    conn.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO,
                    struct.pack("LL", 100, 0))
    print('Nueva conexión UDP')

    # inicializar el mundo
    newthread1 = threading.Thread(target=UDP_rdr,
                                  daemon=True,
                                  args=(conn, conn2, data))
    newthread1.start()
    TCP_rdr(conn2, conn)
    print('TCP rdr retorna, esperando UDP_rdr...')
    newthread1.join()
    conn2.close()
    print('Cliente desconectado')
Esempio n. 3
0
# Echo client program
import jsockets
import sys

s = jsockets.socket_tcp_connect('localhost', 1818)
if s is None:
    print('could not open socket')
    sys.exit(1)

s.send(b'hola')
data = s.recv(1024)
s.close()
print('Received', repr(data))
Esempio n. 4
0
#!/usr/bin/python3
# Echo client program
import jsockets
import sys

if len(sys.argv) != 3:
    print('Use: '+sys.argv[0]+' host port')
    sys.exit(1)

s = jsockets.socket_tcp_connect(sys.argv[1], sys.argv[2])
if s is None:
    print('could not open socket')
    sys.exit(1)

for line in sys.stdin:
    s.send(line.encode())
    data=s.recv(1500).decode()
    print(data, end = '')

s.close()
Esempio n. 5
0
# echo proxy 2
# TCP Client
# UDP Server
import os
import signal
import sys
import jsockets

sServer = jsockets.socket_tcp_connect(sys.argv[2], sys.argv[3])
if sServer is None:
    print('could not open socket for Server')
    sys.exit(1)

sProxy = jsockets.socket_udp_bind(sys.argv[1])
if sProxy is None:
    print('could not open socket for proxy1')
    sys.exit(1)

print('Cliente Conectado')
while True:
    data, addr = sProxy.recvfrom(1024)
    if not data:
        break
    sServer.send(data)
    data2 = sServer.recv(4096)
    sProxy.sendto(data2, addr)

sProxy.close()