All pastes #19492 Raw Edit

Miscellany

public text v1 · immutable
#19492 ·published 2005-08-07 13:14 UTC
rendered paste body
import GameLogic as g
import socket
import threading

c=g.getCurrentController()
o=c.getOwner()

def connect():
	mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
	#Next, open your server program. We will now connect to the server:
	mySocket.connect ( ( '127.0.0.1', 8000 ) )
def share():
	#This should look very familiar to the bind method, with the exception of the first argument, which tells our socket where to connect to. We now need to send our server a message:
	mySocket.send ( socket.gethostbyname(socket.gethostname()) )
	#You should now see the message in the server window. Let's accept the server's reply:
	print mySocket.recv ( 100 )
def disconect():
	mySocket.close()

class sender(threading.Thread):
    global share
    def run(self):
    	share()
	
if o.init==0:
	connect()
	echo = sender()
	o.status="connected"
	o.init=1
elif o.init==1:
	echo.start()