I am writing a program in which one script (the python script) hosts a server, and the ruby script then connects, after doing so, the python script displays a prompt and sends the data to the connected ruby client, the ruby program then executes the command via system function, my error is the command only executes when you end the connection on the server (python script) so I can send only one command, then end the connection and the ruby script then executes, I want it to run and execute the commands as it receives them. Here are the scripts:
python:
#!/usr/bin/env python
import socket
import time
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.bind(('192.168.1.104',567))
sock.listen(1)
(client,(ip,port))=sock.accept()
print('[*] Connection from {} via port {}').format(ip,port)
while True:
cmd = raw_input("# ")
client.send(str(cmd))
Ruby:
class C
attr_accessor :clr
end
r = C.new
r.clr = "\033[0;31m"
d = C.new
d.clr = "\033[0;00m"
require 'socket'
def sock_setup(address,port)
@addr = address
@port = port.to_i
@socket = TCPSocket.open(@addr,port)
while TRUE
@cmd = @socket.read(1024)
puts @cmd
system(@cmd)
end
end
print("Address=> ")
@host = $stdin.gets.chomp
print("\n")
print("Port=> ")
@port_ = $stdin.gets.chomp
sock_setup(@host,@port_)