Lan game communication?
I'm building a game (probably just like many others in this forum :) and I was wondering how I could implement a LAN multiplayer. I know that there is a module out there called socket, but I am not exactly sure how to use it. And it seems ( correct me if I'm wrong) that it cannot find other players who are up for a LAN game.
THanks in advance,
@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 MultipeerConnectivity defines two modes:
see here the definition taken from apple developer website:
Use this message type for application-critical data.
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