Presentation is loading. Please wait.

Presentation is loading. Please wait.

PeerFinder.Role = PeerRole.Client; PeerFinder.Role = PeerRole.Host;

Similar presentations


Presentation on theme: "PeerFinder.Role = PeerRole.Client; PeerFinder.Role = PeerRole.Host;"— Presentation transcript:

1

2

3

4

5

6

7

8 PeerFinder.Role = PeerRole.Client; PeerFinder.Role = PeerRole.Host;

9 PeerFinder Networking Model Host Client

10 PeerFinder HostClient PeerFinder.Role = PeerRole.Client; PeerFinder.ConnectionRequested += ConnectionRequested; PeerFinder.TriggeredConnectionStateChanged += TriggeredConnectionStateChanged; PeerFinder.Start(); PeerFinder.Role = PeerRole.Host; PeerFinder.TriggeredConnectionStateChanged += TriggeredConnectionStateChanged; PeerFinder.Start();

11 Finding players HostClient PeerFinder.Role = PeerRole.Client; PeerFinder.Start(); // Wait for Host to find and invite client. private async void FindPeers() { progressBar.Visibility = Visibility.Visible; try { var peerInfoCollection = await PeerFinder.FindAllPeersAsync(); if (peerInfoCollection.Count > 0) { // Display nearby clients in a list...

12 Connecting players HostClient – incoming connection request private async void ConnectionRequested(object sender, ConnectionRequestedEventArgs e) { List existingInvitations = new List (); existingInvitations.Add(e.PeerInformation.DisplayName);... ReceivedInvitationsHeader.Text = "STOMP invitations :-)"; progressBar.Visibility = Visibility.Collapsed; } private async Task ConnectToPeers(PeerInformation peer) { progressBar.Visibility = Visibility.Visible; StreamSocket s = await PeerFinder.ConnectAsync(peer); ConnectedPeer temp = new ConnectedPeer(peer.DisplayName); connectedPeers[temp] = new SocketReaderWriter(s, this);... startGameButton.Visibility = Visibility.Visible; }

13 Connecting players (continued) HostClient – connect devices // Navigate client to a new page - WaitingForHost... { backButton.Visibility = Visibility.Collapsed; WaitingForHostParameters parameters = (WaitingForHostParameters)navigationParameter; StreamSocket socket = await PeerFinder.ConnectAsync(parameters.peer); pageTitle.Text = "Connected! Waiting for Host...";... } // Host connecting to client...

14 ConnectedPlayers.Items.Add(peer.DisplayName);

15 Tap and connect HostClient – connect devices private async void TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs e) { if (e.State == TriggeredConnectState.PeerFound) { // Show indeterminate progress UI } else if (e.State == TriggeredConnectState.Completed) { StreamSocket socket = e.Socket; WaitForHost(socket); } else if (e.State == TriggeredConnectState.Failed) { // Inform challenger that connection failed } private async void TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs e) { if (e.State == TriggeredConnectState.PeerFound) { // Show indeterminate progress UI } else if (e.State==TriggeredConnectState.Completed) { socket = new SocketReaderWriter(e.Socket, this); } else if (e.State == TriggeredConnectState.Failed) { // Inform Game Leader that connection failed }

16 Sending/Receiving data - timer HostClient public async void ReadMessage() { // Read incoming message from the socket uint bytesRead = await dataReader.LoadAsync(sizeof(uint)); uint messageLength = dataReader.ReadUInt32(); bytesRead = await dataReader.LoadAsync(messageLength); currentMessage = dataReader.ReadString(messageLength);... } private int ParseMessage() {... case Constants.OpCodeUpdateClientTime: if (gamePage != null) gamePage.UpdateClientTime(words[1]); break; private void UpdateTime(TickOption option) { // Decrement the timer by 1 second foreach (SocketReaderWriter tempsocket in connectedPeers.Values) { string message = string.Format( "{0} {1}", Constants.OpCodeUpdateClientTime, timeLeft.ToString(@"m\:ss")); tempsocket.WriteMessage(message); } }

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56


Download ppt "PeerFinder.Role = PeerRole.Client; PeerFinder.Role = PeerRole.Host;"

Similar presentations


Ads by Google