Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Network Broadcast Listener

Author
Message
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 21st Jan 2012 20:20 Edited at: 5th Feb 2012 21:07
Hence this createBroadcastListener(45631) command... I'm a bit stuck on how exactly it can be used. I have no issue picking up the data it sends, but all I get is an id and the name of the host's game, no ip. The documentation is a bit vague, has anyone successfully used this command set?

_____________________
the listener shares

a) string including game name
b) integer including port
c) string including ip [Tier 2 only]

GetNetworkMessageFromIP() is used for Tier 1

swis - No, it's not pokemon.
Joined: Tues Dec 16th 2008
Mod = Troll - http://forum.thegamecreators.com/?m=forum_view&b=2&t=114323&p=586
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 24th Jan 2012 18:25
Hmmm... this silence must mean no one else has had much success. Well, so far I've noticed the first 4 characters in the host game's name are cut off, though the length of the string remains persistent. So
Interstellar: Between the Stars
becomes (for the client after pickup)[_ are spaces]
rstellar: Between the Stars____

The only other information I get is a 31, the first value sent. I'll most likely update my other thread so anyone here can see the issue...

swis
No, it's not pokemon.
Joined: Tues Dec 16th 2008
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jan 2012 21:17
I'm just about to try this, so I will let you know.

31 is the ASCII character before SPACE, maybe this is a special character in network messages?

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jan 2012 22:26
OK...some success!

It has worked for me. I ran my program on my laptop, and then a second or two later on my Android phone. In the following description, an "Instance" is a networked game on a specific port. My process is:

1. Listen for existing Instances (for 3 seconds) and record them
2. Check my game name doesn't exist. If it doesn't, create instance (HostNetwork())
3. Listen for Instances again to see what I find.

This is what happens at each step:


Laptop (runs first)
1. Get 1 message every second (Message No. + Message String)
. 10001 : App Control Network
. 10002 : App Control Network

2. Instance Created (Game9872)

3. My game name broadcast once a second
. 10003 : Game9872
. 10004 : Game9872
. 10005 : Game9872


Phone (runs second)
1. Get 1 message every second (Message No. + Message String)
. 10001 : Game9872
. 10002 : Game9872

2. Instance Created (Game1041)

3. Both game names broadcast once a second
. 10003 : Game9872
. 10004 : Game1041
. 10005 : Game9872
. 10006 : Game1041
. 10007 : Game9872
. 10008 : Game1041

--------------

I'm getting the full game name, but it is only short.
Once you have this name, you should be able to JoinNetwork() by name on the Local network. On a Remote network, you'd have to do something clever like put the port number in the name.

If you are likely to have more than one Instance on the network, you'd have to do something like have a "GetPort" message to record port numbers in use on the network, so you don't use an existing one.

My code for checking for Instances:



My code for hosting a network:



LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 27th Jan 2012 01:10
@swissolo : Did this work for you? It's pretty deep stuff for the beginner, and I hope Steve's article helped you out.

I drink tea, and in my spare time I write software.
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 29th Jan 2012 00:46
I'm afraid I haven't. I'll probably have to put some extra code together to test the full extent. Thank you very much though BatVink. It did tell me I'll have to join through game names as opposed to the usual ip. Unfortunately, my game titles are still shifted four characters to the right, no matter what I do. Even if I add these four characters back (such as "game"), the spaces at the end nullify the connection (I'm unaware of any "substring" like commands. I suppose each character could be pulled into an array, then further editted, but I don't know if others have this issue.) I'm a bit stumped. I can tell you the networking functions other than the broadcasting ones have worked flawlessly. I'll eventually post a demo of the action in my other thread, maybe with the old non-listed connection. We'll see. For the time being... have any ideas for a workaround?

swis
No, it's not pokemon.
Joined: Tues Dec 16th 2008
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Jan 2012 10:35
I can't see why you're getting this problem, here's a few things to check....

1. getBroadcastMessage() is immediately followed by getNetworkMessageString(bm).

2. You are not using port 45631 for anyhting else

3. You are deleting the message once processed

4. You are reading all broadcast messages in a loop once you start reading. Don't stop once you have a hit (even if you only have one instance), the system needs to know you read them all.

swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 29th Jan 2012 22:17 Edited at: 29th Jan 2012 23:00
Success!
I had mentioned I was recieving a 31 at the start. Well, that was from when I originally tested to see what pieces of data would be received. I anticipated an 1) ID 2) Name 3) ip. Of course, your code showed me that it didn't in fact share the ip in the broadcast, nor any id, but I accidentally left that bit of code on top. It's always those careless mistakes isn't it? I was dumping off an integers worth of data (option #1 ) It should probably be clarified in the documentation that only the game's name is sent. Otherwise, I'll post up my progress on Interstellar since it finally works. Thanks so much for all the attention and time that's gone into me. Wouldn't have been able to do it without you

Edit: There's no way to join a game using the name and port is there? I suppose I'd have to include an ip, then add a character like * (that I could later find with the left() string commands and such) followed by the port.

swis
No, it's not pokemon.
Joined: Tues Dec 16th 2008
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 30th Jan 2012 17:14
Quote: "It should probably be clarified in the documentation that only the game's name is sent."


It would be even better if it was followed by the IP address and port...maybe it does and I haven't looked far enough into the message. One problem I'm trying to overcome is working out which ports are already in use, where you have more than one game on the network.

Quote: "There's no way to join a game using the name and port is there?"

The name encompasses the IP address and port into one piece of data. Adding the port would be like specifying the port twice in the request.

swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 30th Jan 2012 22:22 Edited at: 31st Jan 2012 22:57
Quote: "It would be even better if it was followed by the IP address and port...maybe it does and I haven't looked far enough into the message."

Yeah. I don't think it does though, I've checked before (ran me into a bit of trouble doing it), never know though.
Quote: "One problem I'm trying to overcome is working out which ports are already in use, where you have more than one game on the network."

How about just including the port as the game's #. That way, you already check for unique game names, and ports are therefore open aswell. I've mostly been worrying about accidentally hitting ports used by other programs and such. No way to do that Tier 1 that I know of.

Quote: "The name encompasses the IP address and port into one piece of data. Adding the port would be like specifying the port twice in the request."

Oh. Thanks for the clarification. I just can't wrap my mind around the game titling. I'm so accustomed to an ip and port.

swis
No, it's not pokemon.
Joined: Tues Dec 16th 2008
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 30th Jan 2012 23:39
Quote: "Quote: "It would be even better if it was followed by the IP address and port...maybe it does and I haven't looked far enough into the message."
Yeah. I don't think it does though, I've checked before (ran me into a bit of trouble doing it), never know though."


Good news..it does! I had been checking for a second network string. I spoke to TGC Paul and said "Wouldn't it be good if you added the port to the broadcast. His reply..."It does, use GetNetworkMessageInteger() after retrieving the name.

I tried it and yes, I get the port number. Apparently you can get the IP address too in Tier 2, and Paul has made a note to add it to Tier 1 in a future update.

So we can use the broadcast listener to make sure we don't use a port that is already in use by another game.

swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 30th Jan 2012 23:45
Quote: "Good news..it does! I had been checking for a second network string. I spoke to TGC Paul and said "Wouldn't it be good if you added the port to the broadcast. His reply..."It does, use GetNetworkMessageInteger() after retrieving the name.

I tried it and yes, I get the port number. Apparently you can get the IP address too in Tier 2, and Paul has made a note to add it to Tier 1 in a future update.

So we can use the broadcast listener to make sure we don't use a port that is already in use by another game."

That simplifies it a lot! When I had pulled off the integer at the beginning, I probably left nothing afterwords to find I wonder why the ip is only included in Tier 2 at the moment. Seems a bit odd, I suppose it wasn't in the original build, and was easier to test and add to Tier 2? Oh well, once again, very helpful, thanks

swis
No, it's not pokemon.
Joined: Tues Dec 16th 2008
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 1st Feb 2012 17:02
Just had another look into the networking code and realised that GetNetworkMessageFromIP() allows you to get the IP in tier 1, tier 2 is slightly different as it returns everything in a single command.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Feb 2012 15:25
Fantastic, the full story is complete.

I'd assumed (wrongly) that this command requested a message from an IP address.

Login to post a reply

Server time is: 2024-04-26 15:03:51
Your offset time is: 2024-04-26 15:03:51