How to make a multiplayer game from scratch: Establishing a connection between a python socket server and Flash socket

Subscribe to How to make a multiplayer game from scratch: Establishing a connection between a python socket server and Flash socket 4 posts

avatar for qwerberberber qwerberberber 508 posts
Flag Post

A look at the code first:

server side (python):

#import the library for connection
import socket

#going to make a server locally
HOST = "localhost"
#port
PORT = 1337
#put these 2 pieces of data in a tuple
ADDR = (HOST,PORT)
#buffer size
BUFSIZE = 4096

#create a socket object representing the server
serv = socket.socket(AF_INET,SOCK_STREAM)
#associate with the right address
serv.bind((ADDR))
#listen for 1 connetion
serv.listen(1)
#accept; this is where the program hangs and awaits a client connection
#this is where the client (flash) uses the connect function
conn,addr = serv.accept()

#the program also hangs here in waiting of data sent from the client
data = conn.recv(BUFSIZE)
#display the data, should be hello
print(data)

client side (haxe/AS3):

//define the host
var host:String = "localhost";
//define same port
var port:Int = 1337;

//create socket object
var s:Socket = new Socket();
//continue code after connection is established
s.addEventListener(Event.CONNECT,done);
//connect to the according serer
s.connect(host,port);

//function done
//write a message to the buffer
s.writeUTFBytes("hello");
//send message
s.flush();

This is the most simple demonstration of connection between a server and flash. With this you can program the game in python and send user input from flash to python, then send the players updated coordinates from python sever to flash.

However, since I am working in haxe, the best method would be to program the server in haxe also and compile that to a java server or a C++ server.

 
avatar for Drakim Drakim 1154 posts
Flag Post

Neko is also a surprisingly good server language. It’s much more lightweight than Java. But the 31 bit ints really piss some developers off, lol.

 
avatar for truefire truefire 3011 posts
Flag Post

I think Nicolas actually added some kind of optional ‘use 32 bit integers’ compiler argument for Neko, iirc.

 
avatar for BobJanova BobJanova 860 posts
Flag Post

I have a partial Flash client to go with this C# messaged socket class if that’s of interest to anyone. I want to make it do the RSA handshake though, so if anyone has tips on how to do RSA in Flash (in a compatible way to the .Net implementation) I’d appreciate that.