Hi everyone again:P Here is some code for you newbies like me that want to use networking with your games, its simple and down the core of the program with a little chat pro-app. It just shows how a server can handle more then one client. You can open the client setup as much as you want.
Also for client put in your ipaddress (open cmd and type in ipconfig if you dont know it). If it sucks, then sorry lmao XD
Server:
import SocketServer
class EchoRequestHandler(SocketServer.BaseRequestHandler):
def setup(self):
print self.client_address, 'connected!'
def handle(self):
while 1:
data = self.request.recv(1024)
print data
if data.strip() == 'bye':
return
def finish(self):
print self.client_address, 'disconnected!'
#server host is a tuple ('host', port)
server = SocketServer.ThreadingTCPServer(('', 5000), EchoRequestHandler)
server.serve_forever()
Client:
import socket
tcpstock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
tcpstock.connect (("YourIpAddress", 5000))
while (1):
data2 = raw_input('You>> ')
tcpstock.send(data2)
if data2 == "bye":
tcpstock.close()
print "You have disconnected!"
break