2

I am having a little trouble with the windows 8 store apps. My question is simple:

I have a windows 8 store app on 1 pc, and the same app on another pc. The PCs are not in the same network, but have internet. I want to send a message (string/bytes) from PC A, to PC B.

How can I do that?

EDIT:

OK, the StremSocket connection works. I successfully sent data from PC A, to PC B. I will write a simple demo to demonstrate it. Now comes the tricky part - the discovery.

My idea is simple: Make an Azure service which holds a database whith the peers in the form (ip,port,timeout). There will be a few rules.

  1. When you make "server", the app will notify the service every 1 second for it's existance.
  2. When the service recieves data from an app in the form (ip, port), it will check if this entry exists in the database:
    2.1 If yes - reset the timeout of the entry to 0
    2.2 If not - insert the server in the database with initial timeout 0
  3. Every second the service will update the database by these rules:
    3.1 Increase the timeout of every entry by 1
    3.2 If an entry has a timeout>5 (has not reconnected for 5 seconds) - remove it.

I'm sure there is a smarter solution, but this one seems like little work, and I think it should work for my needs. What do you guys think?

Mario Stoilov
  • 3,411
  • 5
  • 31
  • 51
  • Have a look at http://stackoverflow.com/questions/7507155/no-p2p-in-windows-metro-applications – Daniel Kelley Jan 27 '13 at 17:05
  • The first question is how your two peers will discover each other. – Eugene Mayevski 'Callback Jan 27 '13 at 17:19
  • The discovering part is not the problem here. On the p2p part. Read the link and I can say that the app will most likely NOT run in background, so just being able to send/receive data will be sufficient – Mario Stoilov Jan 27 '13 at 18:36
  • @MarioStoilov I think he means, how will the two clients know where the other client is located? – N_A Jan 28 '13 at 03:47
  • Well position shouldn't be of interest, but I think you mean how will they know that they exist. I'll probably have a dedicated server, which will keep a list of available peers – Mario Stoilov Jan 28 '13 at 11:01
  • @MarioStoilov If you want your additional question answered, then you should post a new question. – N_A Feb 14 '13 at 23:56
  • @MarioStoilov Hey did you ever figure this out? We're trying this in JavaScript. Any information will be helpful. – Jacob Morrison Apr 03 '13 at 00:35
  • Well if you're asking about the server part - almost yes. There are a few hiccups that need fixing, but lately I don't have the time to look them up. Ask what you need – Mario Stoilov Apr 04 '13 at 09:13
  • @MarioStoilov How were you able to obtain the interface (ip and port) for the listening StreamSocket that the other client could connect to over the web? It seems like the would be issues with router firewalls and whatnot. Also when you reply can you use the @ to mention me, so I get the notification of your reply? Thanks Mario – Jacob Morrison Apr 04 '13 at 16:00
  • @JakeMorrison Well these are just the hiccups I was talking about. When you launch the app and create a server you automatically connect to an azure service(or whatever service you wish to use) where a Database of all the active servers are kept. You tell this server "Hey I just hosted sever. My ip is .... and the port is....". This is the first problem, because you rely on the info you are sent and sometimes it may be misleading. On the service you have a script that tries to ping every entry in the DB in some interval, and if, lets say you fail to ping 5 times in a row - the entry is removed – Mario Stoilov Apr 05 '13 at 16:31
  • @JakeMorrison On the clientside it's similar. You connect to the DB and ask "Hey, could you tell me what servers are available" and the DB gives you all the adresses and their ports that are currently on that DB and using that information you try to connect to other servers. On the issue with the routers and firewalls - that is the users responsibility. The firewall/riuter port blocking is designed just for that purpose - denying connections wether if it's the users choice or the administrations choice. If you have any more questions please pm me, because these comments are too short – Mario Stoilov Apr 05 '13 at 16:35

1 Answers1

2

I think the StreamSocket is what you want. This will allow connection and back-and-forth communication between two clients. If you want them to be able to find each other you will probably have to provide a service hosted on a server somewhere which will list the available client connections.

N_A
  • 19,799
  • 4
  • 52
  • 98