GameKit: send additional information using GKSession without actually connecting?

I am working on an iOS application that allows users to share PDF files with other devices locally. When the application starts the device, it becomes a client that searches for servers that transfer files. When the client sees the server, he adds an icon to his tab and adds an entry to the table.

The problem that I encountered is that GKSession only allows one line to be transmitted before the connection is established. Partner display name. What I would like to convey is the file name, the number of pages, and possibly a thumbnail.

The only way I can think now, to achieve this behavior is to automatically connect the client and servers, exchange information about the files, and then automatically disconnect them. This might work if only one or two files currently exist, there will probably be problems with streams / synchronization when many different devices are broadcast.

For example, 7 files may be available. Thus, the client will have to connect to them one by one in order to receive information about all the files. This will probably take a lot of time, and the user may have already decided that they want to download file 1. By clicking "file 1", you need to establish a connection and start the transfer. This may not happen instantly if the client is busy retrieving information about other available files.

I also read some problems connecting to the server shortly after it was disconnected .. ( what does GKSession not connect with every attempt? ).

So, I think it comes down to simple questions. Does anyone have any ideas how I can let the client get additional information about the server except peerID and peerName?

+4
source share
2 answers

How to set the display name in csv format and when you get the csv name, display only the device name.

Or you can send the JSON string NSDictionary as the display name

Json example to go to NSString:

{ "DeviceName" : "Example", "File" : [ { "FileName" : "PDF1" "TotalPages" : 100 } ] } 

Stringified version:

 {"DeviceName" : "Example","File" : [{"FileName" : "PDF1","TotalPages" : 100}]} 

Then, when you get DisplayName, show only DeviceName and analyze the file data somewhere to send requests for the server at a later date.

Keep in mind that I don’t know if GKSession has a restriction on the display name length, so this solution may not work with a large number of files.

+2
source

What I did was limited the display name to 16 characters and used the remaining 24 characters for my use.

I created offsets from which to read various information needed for the application. For example, from 0 to 15, the device name will be displayed; 16-24 will represent the file extension. 24-39 will represent the file name. If the string is larger than its corresponding space, then it is trimmed or truncated depending on what you prefer. If the line is shorter than its corresponding space, it is filled with spaces. I wrote methods to get these strings from a 40-character display name. If anyone has a better solution, I will be happy to have them here. I can’t send the code at the moment because I do not have access to it.

Greetings

0
source

Source: https://habr.com/ru/post/1438978/


All Articles