Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SFML Game Development.pdf
Скачиваний:
194
Добавлен:
28.03.2016
Размер:
4.19 Mб
Скачать

Company Atop the Clouds – Co-op Multiplayer

It is this simple; you create the sockets, add them to the selector, and then call sf::SocketSelector::wait(). When it returns, you know one of the sockets received something or a new peer has been connected. You just check who that was by using sf::SocketSelector::isReady(socket) and then act upon it.

Custom protocols

We've talked about TCP and UDP so far, which are two socket types that are used widely. Programmers don't usually program anything that is "lower-level" than those two, but very often build custom protocols on top of them.

It is very useful to create such protocols as they allow us to abstract the more complex tasks of networking, and orient a network system into being more focused on a specific task. For a quick example, we can look at the FTP protocol. It allows sending files in a quick and simple way, because it has abstracted the more complex process of actually transferring that file over a lower-level protocol.

A custom protocol is merely a set of rules set in stone of how communication needs to happen. When a custom protocol is created, it either sits on top of TCP or UDP or even both; but it automatically absorbs all advantages and limitations of the underlying protocol.

There are many custom protocols that are used widely. For example, HTTP and FTP are two protocols that are used worldwide and are implemented on top of TCP/ IP. You use them all the time without knowing; for example, when you open a web

page in your Internet browser, it was received through the TCP/IP network protocol, more specifically with the rules of the HTTP protocol.

As if SFML's basic socket support weren't good enough, it also implements sf::Http and sf::Ftp, which you can use to communicate with any machine that is implementing them too! This is a fantastic tool that you can use to your advantage, for example, to directly transfer files to FTP servers, or to request web pages from remote hosts using HTTP. We won't cover such classes, as they go out of the scope of the book, but to bring up your curiosity, you could use sf::Http to send some data to a website that would handle it and do something useful with it. For example, that website could receive a high score information and immediately list it online for everyone to see!

We will be implementing one custom protocol as well in the upcoming section

Creating the structure for multiplayer. It will be our own set of rules that are specific to our own game. It will lie on top of the TCP/IP protocol and you will just see how it can be used to make multiple instances of our game understand each other.

[ 240 ]

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]