Real-time communication over a network / the internet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    Real-time communication over a network / the internet

    I'm looking for a solution for something I've been interested in for quite some time. I'd like to build an application that allows users to communicate with each other in real-time, like an instant messaging application. I learned how I can create an application that will respond to a request sent on a specific port from another application, but I didn't try this over the internet.

    I'm thinking push technology, where I make a change on my side and anyone else using the program will see those changes at the speed of internet, i.e. without having to actually look for the update. I know it's possible, Live Messenger, Skype, and any other instant messaging program can do it.

    I can't exactly explain what I intend to do with this because it's not fully fleshed out yet, but it will have a purpose. Basically I want to create an always-on application that I can send messages to, like a notification of an update, and have it show up "instantly" on the client's screen.

    On a side note, I know I could simply have the program check for any changes at a high interv al, like once a second, but that might not always work if it takes longer for the request to take place than the defined interval, plus it generates a lot of overhead. Instead of the client asking the master for an update, the master will tell the client that an update is available as soon as it becomes so.

    Is this possible, and am I making sense?
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    #2
    Is this not possible, or did I not explain clearly enough what I was trying to accomplish? I've looked all over and I can't find any helpful information.

    Comment

    • Alex Papadimoulis
      Recognized Expert New Member
      • Jul 2010
      • 26

      #3
      The biggest problem you will run into is NAT and firewalls. For example, at work, we have a single public IP address that is NAT'ed to 50+ computers. Even without a firewall, there would be no way for your server to talk to one of our computers: the IP belongs to the router.

      So, the only way around this is to have a client program (inside of a private network) open up a communication channel with your server (accessible via public IP). TCP and UDP are protocols generally used for this. In the .NET world, these are programmed using Sockets.

      Comment

      • HaLo2FrEeEk
        Contributor
        • Feb 2007
        • 404

        #4
        Well then I'll have to use Sockets. I know this has to be possible, Windows Live Messenger does it, even on a network where the the IP belongs to the router. I have a server that I was planning on using. Basically I'd change a setting on my computer, which would send it to my server, which would broadcast it to all the "listening" apps, without those apps having to explicitly "ask" for updated information. Would that be possible?

        Comment

        • Alex Papadimoulis
          Recognized Expert New Member
          • Jul 2010
          • 26

          #5
          Windows Live Messenger ("Client") connects to publically-accessible Microsoft server. The Client stays constantly connected and, essentially, listens for messages from the Server.

          One way to do this would be with a UdpClient:
          Code:
          var client = new UdpClient(12345); // Local Port 12345
          client.Connect("yourserver.com", 67890); // Remote Port 67890
          
          var remoteEndpoint = new IPEndPoint(IPAddress.Any, 0);
          
          // ... snip ...
          
          while (client.Active)
          {
            if (client.Available)
            {
              var message = client.Receive(ref remoteEndpoint);
              ProcessMessage( message );
            } 
            Thread.Sleep(100); // wait .1 seconds
          }

          Comment

          • HaLo2FrEeEk
            Contributor
            • Feb 2007
            • 404

            #6
            Would I need something running on my server for this to work? For example, if I made an "admin" program, from which I could send messages to my server to be resent to all listening "client" programs, would I need something on my server to listen to and resend that message?

            Comment

            • Alex Papadimoulis
              Recognized Expert New Member
              • Jul 2010
              • 26

              #7
              Yes, your admin program would simply use the Send method, which you'd obviously code for. Dont' forget about authentication, since you don't want just anyone to tie into this admin hook.

              Comment

              • HaLo2FrEeEk
                Contributor
                • Feb 2007
                • 404

                #8
                I'm on shared hosting, using a Linux server. How would I accomplish this?

                Comment

                Working...