Results 1 to 13 of 13

Thread: Ping a program running on some IP via the internet

  1. #1

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,600

    Ping a program running on some IP via the internet

    Ok, I'm playing with a concept that is new to me. I'm more of the end-user working-on-LAN application guy.

    I've got an idea I'd like to play with. But baby-steps.

    Let's say I want to setup a (sort of) server with a few clients over the web. The server program is really no different from the client program, other than it's the one who manages communications. (I'll think about full peer-to-peer later.)

    And, a couple of ground-rules:
    1) I'll know all the IP addresses (possibly creating a DB with usernames for them).
    2) Initially, I'm not terribly worried about any high-level security.

    The first baby-step is figuring out how the server can ping the client to see if they're there. And that's my question. What's the easiest way possible for just minimal data transfer from IP to IP, eventually in a small hub-and-spoke configuration with a server and maybe 10 clients.

    In these Covid 19 days, a friend has given me an idea to start writing some open source internet games. If I get a foundation up and running, I'll talk more about the actual games.

    Thanks In Advance,
    Elroy

    EDIT: Oh, one more thing. I'd like to do this without using any OCX files and/or any third-party DLL. If possible, I'd like to do it with fairly obvious API calls.
    Last edited by Elroy; Mar 28th, 2020 at 11:43 AM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  2. #2
    Fanatic Member
    Join Date
    Feb 2019
    Posts
    706

    Re: Ping a program running on some IP via the internet

    You would have to send some data, and get a response back on the same connection/port that you are using, to make sure that firewalls are not blocking the traffic.

    There are samples that send Ping from VB6, like this one, but it's not a reliable method. Pings could be blocked, while other traffic is allowed and vice versa, because they use different ports. However, generally; clients can ping servers(because they must allow incoming traffic, and ping port unblocked), but servers can't ping clients(because it's a bad idea to allow clients to accept connections, or they are behind a NAT; multiple clients sharing the same IP, but different dynamic ports).

    Another difficulty is that TCP is a byte stream without concept of packets. If you want packets, you have to make it on your own. The easiest for non-binary is to use a certain character as a terminator. For binary data, the easiest is a counter(one byte), followed by 0-255 of data. I have implemented a 32-Bit counter followed by data, and it wasn't easy. Regardless of the method, you have to reassemble the "packets". In one DataArrival event, the only thing that you are guaranteed to receive is one or more bytes, not necessarily your packets. You could receive half a packet, then the other half in another DataArrival, or multiple packets at once with the last byte being a counter at the end, so you have to slice the packets as you go. This is harder if the counter is more than one byte, because you could receive them at one byte each, or one-two-one for 32-Bit, so your algorithm need to take account for that. I had to test my routine for all these cases by calling it with test byte arrays, to make sure that all these situations are accounted for. It took me a long time to get it right, so unfortunately, I can't post it here.

    Off topic: I have some ideas for games too, but more for fun than making money. Unreal Engine has a visual flow chart method called Blueprint. It has graphical constructs for programming elements like For loops, etc, so it's easier for a programmer to use, and I think it supports multiple players over the Internet, but I am not sure. The other popular engine is Unity, and the only option is C#. Both engines are multiplatform and can run on mobile devices, and both engines are free until you hit a revenue threshold. Unreal takes 5% after a certain revenue threshold($100K?), while Unity is free for personal use, $400/Year for business. There are plenty of YouTube videos showing how to develop games by using these engines. Try "Unreal Blueprint", just make sure that you are viewing recent videos.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,486

    Re: Ping a program running on some IP via the internet

    "Web" is not a synonym for TCP/IP or the Internet. "Web" normally implies TCP carrying HTTP and/or HTTPS, in turn carrying HTML page markup and related assets such as images or CSS.

    Instead you are probably talking about TCP carrying some ad-hoc application protocol. Unless the entire thing is restricted to a LAN you'll also have to deal with NAT-traversal and port mapping. Without fixed IP addresses things only get that much dicier. Even on a LAN though you have the issue of poking holes through software firewalls these days.

    Most of these issues have been covered either here or in the CodeBank over the past 20 years.

    Your "ping" issue probably needs more elaboration though.

    TCP clients normally connect to the server. So the server becomes aware of a client when it makes a connection request. It is hard to see the need for any "pinging" at all under normal circumstances unless it is very important for the server to quickly discover a dropped client connection.

    That's also a topic that has been discussed here at length many times.

    I don't know of any VB6 wrappers around the Winsock API that work as well or as cleanly as the Winsock control that comes with VB6 though.

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,091

    Re: Ping a program running on some IP via the internet

    > I don't know of any VB6 wrappers around the Winsock API that work as well or as cleanly as the Winsock control that comes with VB6 though.

    Have you tested the VbAsyncSocket single class winsock wrapper? It's a couple of years old effort and has a Winsock replacement control in the making too.

    cheers,
    </wqw>

  5. #5
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,070

    Re: Ping a program running on some IP via the internet

    A server cannot reliably or easily ping clients. For one thing, the ping command utilizes UDP, which is one way traffic only. A connection is never established between 2 end points, so the only way to identify if the other end got the signal is to wait for a reply with a timeout.

    The second problem is that many clients sit behind a built in firewall called a NAT router. The easiest and most reliable way is to have the clients establish the connection to the server using TCP, and once connected they would periodically send a small "heart beat" packet to maintain the connection. The client would automatically establish the connection on boot up and start sending the "heart beat" packets. If the server fails to receive the "heart beat" signal, it disconnects the client. If the client fails to be notified that the "heart beat" was received, it would attempt to re-establish the connection.

    I have several programs that utilize this principle, some of which have been posted to VBForums.
    http://www.vbforums.com/showthread.p...-Personal-Chat
    This is a relatively simple Chat program that allows 2 parties to pass messages via the server. The connection to the server is maintained with a "heart beat".

    http://www.vbforums.com/showthread.p...cure-Messaging
    This is a more complex application that allows 2 parties to send encrypted messages directly to each other. The server is only used to allow the 2 parties to connect to each other, but each client uses a "heart beat" signal to maintain the connection to the server. The connection to the server is established on boot up, and if the connection is lost for any reason, it is re-established. For example, the connection would be lost when the client computer goes to sleep, but would be re-established when the computer is woken up.

    J.A. Coutts

  6. #6
    Hyperactive Member
    Join Date
    Jun 2019
    Posts
    326

    Re: Ping a program running on some IP via the internet

    Hi, Elroy! You can check my answer in another thread where I present different idea about "pinging": Pinging Multiple Machines

    Usually pings on application level are using TCP/IP instead of ICMP and are used for heath checks - exactly what you want to achieve. Also you can send in the "ping" data some more info than "here I am" message.

    If your server app keeps all recent clients (who are healthy) you can send to single one or multiple clients a message. If client needs to send message to other client (e.g. "I am moving hero to position E5") the command may

    For the messages format I personally will stick to simplified binary protocol with command first, length of data and then the byte array of the data. The real data sent will use own specific (for the application) protocol but with the specific fields. This way the communication layer will work without knowing what the app logic is and blindly encapsulate client(s) data. You can check in more details the communication server I use (NATS) for really good details, including the protocol they are using. And finally, the author of NATS wrote the first version in Ruby for a weekend, so I am sure it can be easily done in VB6 too.

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,091

    Re: Ping a program running on some IP via the internet

    Quote Originally Posted by peterst View Post
    . . . so I am sure it can be easily done in VB6 too.
    Not so easily as VB6 is missing basic building blocks for cobbling scalable servers of any kind -- namely multi-threading and/or channels-coroutines and/or async-await the way modern languages are providing these facilities.

    There are some efforts on multi-threading in the community here but none on channels for instance, while async/await are language features no one can implement as of now.

    cheers,
    </wqw>

  8. #8
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    445

    Re: Ping a program running on some IP via the internet

    Quote Originally Posted by Elroy View Post
    The first baby-step is figuring out how the server can ping the client to see if they're there. And that's my question. What's the easiest way possible for just minimal data transfer from IP to IP, eventually in a small hub-and-spoke configuration with a server and maybe 10 clients.
    If you are making a turn based game (poker, chess, etc) you should be able to do everything with http. This is a great starting point: http://www.vbforums.com/showthread.p...her-Web-Server

    If you are doing winsock, the control array will tell you who is connected. You will just want to the client to initiate the initial connection at startup so it can poke through any firewalls.

  9. #9

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,600

    Re: Ping a program running on some IP via the internet

    Quote Originally Posted by DllHell View Post
    If you are making a turn based game (poker, chess, etc) ...
    That is exactly what I'm thinking. My concept is to have a "controller person". We'll also have him run his/her software in some kind of "server" mode. And then, that person can "invite" others to join.

    I'm thinking that "invite" will involve typing in an IP, pinging it, possibly going through a port, and send a message to see of the invitee has the software running in a "client" mode.

    There might be several "clients" that play, but all pretty much controlled by a single "server".

    --------------

    I've got a bit of PhP experience. Maybe I should go look at some of that code. I'm just not sure I can expect each user/client to install a PhP engine though, and I'd like to just keep it all in VB6 (as that's where I code the fastest).

    --------------

    I looked at that "ping" procedure that qvb6 posted, and it certainly works. I now just need to take it to the next step, and have a program on the other end that "listens" for incoming messages and sends a response. It looks like couttsj may have also posted some good ideas.

    All I need is, given known IPs, I need to set up some simple (low bandwidth) communications. It's probably fairly easy. It's just not something I've done before. And, obviously, it's not something VB6 inherently does.

    ---------------

    I'm also finishing up another project, but I'll definitely be getting back to this.

    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  10. #10
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    445

    Re: Ping a program running on some IP via the internet

    Quote Originally Posted by Elroy View Post
    I'm thinking that "invite" will involve typing in an IP, pinging it, possibly going through a port, and send a message to see of the invitee has the software running in a "client" mode.

    There might be several "clients" that play, but all pretty much controlled by a single "server".
    For your own sanity, I'd strongly recommend rethinking this.

    It would require each client to configure their firewalls to allow traffic on the specified port. Which sounds easy enough on the surface but there will be several people who do not know their router password which means calling the isp\vendor or resetting the router to factory default. Then you will need to deal with any McAfee or any other software firewalls. Once it is all setup and working, the dhcp lease will expire and you will need to setup the firewall rules again since their address has now changed. etc etc etc

    You want the "server" to just be "the server" and the clients will connect to it. It will be at a known address and the ports will be opened by you, one time. For 10 clients, your pc at home or any spare POS sitting around should be sufficient and I doubt that the amount of activity would impact your resources much.

  11. #11

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,600

    Re: Ping a program running on some IP via the internet

    Quote Originally Posted by DllHell View Post
    For your own sanity, I'd strongly recommend rethinking this.

    It would require each client to configure their firewalls to allow traffic on the specified port. Which sounds easy enough on the surface but there will be several people who do not know their router password which means calling the isp\vendor or resetting the router to factory default. Then you will need to deal with any McAfee or any other software firewalls. Once it is all setup and working, the dhcp lease will expire and you will need to setup the firewall rules again since their address has now changed. etc etc etc

    You want the "server" to just be "the server" and the clients will connect to it. It will be at a known address and the ports will be opened by you, one time. For 10 clients, your pc at home or any spare POS sitting around should be sufficient and I doubt that the amount of activity would impact your resources much.
    Dll,

    Thanks for the clear advice. Your idea certainly seems reasonable, as the people I'll be targeting will probably also be on a conference call (or Facetime or Zoom). So, if my instructions are clear, it could certainly be a more passive server, with connections established by the clients. Also, I don't think anyone will object to typing in "whatsmyip" into their browsers, for making sure the correct people are connecting up. The server might setup a list of "allowed IPs". Still thinking this thing through.

    Still trying to get another program finished up, but I will be getting back to this. All of this discussion is really great, and lots of food for thought.

    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  12. #12
    Fanatic Member
    Join Date
    Feb 2019
    Posts
    706

    Re: Ping a program running on some IP via the internet

    You could make a networked game without a central server, but a central server is easier to code. One way to do it without a central server is by using UPnP. This is one way XBOX/PlayStation work. They use UPnP to tell the router to open a port, essentially making that client act as a server. However, you may still get tech support calls from people who have trouble connecting. A central server is always a better option.

    I know there are VB6 samples using UPnP, but I don't have a quick line at the moment.

    Edit: Here is a VB6 sample written by dilettante.

    http://www.vbforums.com/showthread.p...-NAT-Traversal
    Last edited by qvb6; Mar 31st, 2020 at 12:08 PM.

  13. #13
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    388

    Re: Ping a program running on some IP via the internet

    Quote Originally Posted by wqweto View Post
    > I don't know of any VB6 wrappers around the Winsock API that work as well or as cleanly as the Winsock control that comes with VB6 though.

    Have you tested the VbAsyncSocket single class winsock wrapper? It's a couple of years old effort and has a Winsock replacement control in the making too.

    cheers,
    </wqw>
    Could it be used to access the messages from a mail server via IMAP over SSL (port 993) ?
    "VB code is practically pseudocode" - Tanner Helland
    "When you do things right, people won't be sure you've done anything at all" - Matt Groening

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width