If anyone can help me, that would be great. I created a python server and client script on Linux with python version 2.6. To my understanding as long as I install the same version of python in Windows, I should be able to run the same script with out a problem. I did this and the script doesn't do anything except print out "Importerror: no module named fcntl". I'm adding the server code and the client. If any one can shed some light on what it is that I'm doing wrong, that would be great. As well, since I'm already here, how can I possibly also get the client side code to run automatically in windows with out having to install python in client side machines.
CLIENT
#!/usr/bin/env python
import socket
import fcntl
import struct
#############################
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
def getHwAddr(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
host = socket.gethostname()
#print host
#print getHwAddr('eth0')
#print get_ip_address(enter code here'eth0')
info = "<"+get_ip_address('eth0')+">","{"+ getHwAddr('eth0')+"}","~"+host+"~"
############################
TCP_IP = 'IP'
TCP_PORT = xxxx
BUFFER_SIZE = 1024
MESSAGE = "Hello, World!"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(str(info))
data = s.recv(BUFFER_SIZE)
s.close()
#print "received data:", data
SERVER
import socket
import re
import subprocess
TCP_IP = ''
TCP_PORT = XXXX
BUFFER_SIZE = 2048 # Normally 1024, but we want fast response
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(50)
conn, addr = s.accept()
print 'Connection address:', addr
while 1:
data = conn.recv(BUFFER_SIZE)
if not data: break
print "received data:", data
da = open("data.txt", "wb")
da.write(data);
conn.send(data) # echo
subprocess.Popen(["python", "ReadandInsert.py"])
conn.close()
Also, quick mention. The server side code will only run in Linux and the client code will be running in Windows. Thank you again for anyone that can lend a hand...!!