Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Lan game communication?
-
Hi,
if it is ios and macOS only then you could also use the native apple multipeer connectivity API for iOS and macOs.Here is a very nice pythonista wrapper which was done by @mikael
https://github.com/mikaelho/multipeer
Especially looking up and finding nearby users is very easy with Apples Multipeer Connectivity.
-
@bennr01 Should the last line of your server code be deeneted? Do you really want to close the socket inside the loop?
-
@ccc the last line does not close the server socket itself. It only closes the just accepted connection. The client also closes immediately after sending "some data". So no reason to not close the connection on server side.
Anyway @bennr01 did only write this as some short demonstration ... In real world you would probably hold the connection open over the whole game session ....
-
@mithrendal this sounds great, I didn't even know that this existed. I'm just looking into it now
-
@Drizzel it depends on what you are planning to develop. If you want local multiplayer then forget about the socket stuff and go with multipeer API. If you want multiplayer over the internet then you go the socket way.
Either way, whish you happy time with sending and receiving data ... it's fun ;-) -
@mithrendal Haha it definitely is fun :)
And it's exactly what I need for my local multiplayer. That it works over Bluetooth as well is a nice add on -
@Drizzel , i just happened to watch this David Beasley YouTube Video today. If you haven't already watched I think you might find it intesting.
-
@Drizzel MultipeerConnectivity defines two modes:
see here the definition taken from apple developer website:
MCSessionSendDataReliable
Use this message type for application-critical data.MCSessionSendDataUnreliable
this message type should be used for data that ceases to be relevant if delayed, such as real-time gaming data.@mikael uses in his wrapper the first one which might not be perfectly suited for gaming, where you simply want no lag at all. But you can patch the wrapper so it sends in MCSessionSendDataUnreliable mode. just look out for the send data method mikael uses for mode a 0 value. Replace it with a 1 value should do. (https://developer.apple.com/documentation/multipeerconnectivity/mcsessionsenddatamode/1407029-unreliable)
in mikaels multipeer.py file, find the following line and change the 0 to 1
self.session.sendData_toPeers_withMode_error_(json.dumps(message).encode(), peers, 0, None)
-
@mithrendal great thanks a lot. Hopefully decreases the lag :)
This may be off topic , but is your name inspired by Gandalf's mithrandir in the hobbit/ lord of the rings? -
@Drizzel I tried my very best to hide my real name but you now uncovered it. Yes I am the son of an uncle of a cousin of gandalf the white! :-)
PS: hope that they don't throw us out of this forum now. Sorry for the off topic ness nature of this post to anyone who's disturbed by it. :-) -
event and rpc based realtime comms