javascript - Running Node.js on iOS as a server and let other device connected in -
i building card game app on ios , android following logic:
- people download app app store / google play
- they can play game offline other players within same wifi-network
- one client act server, while other players act clients
- the game app node.js, sqlite embedded
- each player's move saved in server
- when there's internet access, ios act server send data cloud
my approach is
the game html5 node.js, player act game holder(server) open port (like port 80)
other players use http get/set send , receive json package , game holder
my questions is
will possible me run node.js on ios, server , open ports let other players connect in? can use json communications between players.
if not, best way different device (ios, android, windows phone) communicate?
any suggestions , appreciated. thanks. michael
my reputation not enough comment suggest use anyway. if make server in node.js, rest of answer tell do. use cfnetwork , corefoundation. assuming sending data in string format, code should (the code sends string server).
import corefoundation import cfnetwork var outputstream: nsoutputstream! var writestream: unmanaged<cfwritestreamref>? var addr: cfstring = "127.0.0.1" var port: uint32 = 80 //the second nil in cfstreamcreatepairwithhost read stream. means reads data. don't need bc sending data cfstreamcreatepairwithsockettohost(nil, addr, port, nil, &writestream) outputstream = writestream!.takeretainedvalue() outputstream.delegate = self outputstream.open() outputstream.write("firegun", maxlength: 8 //(the char count of firegun") //close outputstream outputstream.close()
Comments
Post a Comment