473,698 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ping+Port Routine?

Hi! I'm trying to write a small application for an online gaming site
(flight sims), where people can add their local server to a list.

Basically, I just need to be able to loop/ping each respective server
- via a specific port (2934 or 2935) to see whether the server is
still "live", so the hosters don't have to manually update their
status on the site.

Everything I've seen seems overly complex. Efforts so far have
returned info via a traditional PING, but I can't seem to find an easy
way of getting the required *port* info. The script would have to run
from a regular hosted site, so I wouldn't have much access to the
server's "innards".

Any ideas?

TIA - Adam.
Sep 21 '05
13 3234
Adam wrote:
On Mon, 26 Sep 2005 06:59:08 -0500, Jerry Stuckle wrote:

Let's back up a little. I'm wondering if we're looking at the wrong
problem.

A couple of thoughts here. First of all, where are you running the
sniffer? Is it on this machine, or somewhere upstream?

I've got Ethereal running on both machines:

1) Client: Linux - running the PHP script. No firewall.
2) Server: WinXP - running the sim in multiplayer mode. Firewall in
place (Norton PFW) but this server connects OK to other XP machines
running the sim in client mode.


OK, since your client doesn't have a firewall, this shouldn't be a
problem. The reason I asked - if you have a firewall running on the
client, the packets may arrive at the client (and you might see them
with Ethereal), but they may be stopped before they get to the program.
Also, are you using a firewall or a router anyplace? If so, are they
set up properly to pass the incoming data onto your program?

The router only sits between the network and the ADSL.

Anyway - I can *see* the packets leaving/arriving on each machine - so
I think the firewall thing is OK. The packets appear addressed
properly, and contain data.


OK, as long as you can see the packets arriving at the client machine,
you should be OK. I was afraid you might be monitoring them on some
upstream system.
Having done a fair bit of googling around, it seems PHP's sockets
implementation is a bit quirky. All sorts of oddities come into the
equation - the "magic_quot es" setting, stream_set_bloc king and so on.

I could paste the dumps of each packet if that helps any.

Over to you, Mastah! <g>.

Adam.

I don't think the packet dumps will help any more than we already have.

As for the blocking mode - fsockopen() defaults to blocking mode, so the
fread() should block until some data comes in. And if the data do
arrive before you issue fread() (unlikely), the system should buffer it
until you issue fread().

However, this brings up another question. Does the fread() return
immediately, or is there a delay before it returns? I'm wondering if
it's possible that you are timing out on the fread() request. I'm not
sure what the default timeout value is (timeout on the fsockopen only
applies to making the connection) but you can use stream_set_time out()
to set it to a longer value.

I really wish I could be more help here - but this is a problem I
haven't run into before.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Sep 26 '05 #11
On Mon, 26 Sep 2005 13:11:20 -0500, Jerry Stuckle wrote:
OK, since your client doesn't have a firewall, this shouldn't be a
problem. The reason I asked - if you have a firewall running on the
client, the packets may arrive at the client (and you might see them
with Ethereal), but they may be stopped before they get to the program.
Good thought. I hadn't considered the fact that a firewall could do
that. It's just possible that the firewall on the Linux box is
allowing *outgoing* traffic on 2934 but blocking *incoming*. I'll do
some digging around.
As for the blocking mode - fsockopen() defaults to blocking mode, so the
fread() should block until some data comes in. And if the data do
arrive before you issue fread() (unlikely), the system should buffer it
until you issue fread(). However, this brings up another question. Does the fread() return
immediately, or is there a delay before it returns? I'm wondering if
it's possible that you are timing out on the fread() request. I'm not
sure what the default timeout value is (timeout on the fsockopen only
applies to making the connection) but you can use stream_set_time out()
to set it to a longer value.
Invariably, there's a delay. And this is for ALL types of socket read
that I try (simple fread or stream functions). Changing
stream_set_time out() simply makes it sit there even longer - but in
many cases the whole script bombs out after 30 secs. Looking at the
ethereal output, that's around 29.999 secs too long <gg>.
I really wish I could be more help here - but this is a problem I
haven't run into before.


My feeling is that it's to do with the "connection-less" state of UDP
- and that the incoming packet is *not* being buffered by PHP (or the
script has already "missed the boat"). All experiments with TCP work
as advertised.

Are there any simple UDP tests I could try? I found a [local]
time-server script but I don't think I have a time server service
running on that machine, so I got no output either.

In all my googling, I've seen very few comments to convince me that
anyone has actually had UDP sockets working - plenty of reports of
(early) bugs in PHP with sockets though.

Appreciate your input so far - thanks!

Adam.
Sep 27 '05 #12
On Mon, 26 Sep 2005 13:11:20 -0500, Jerry Stuckle wrote:
I really wish I could be more help here - but this is a problem I
haven't run into before.


Jerry - success!!!

I finally got it working - but what an ordeal!!

1) It seems that socket support in PHP is "flakey" to say the least. I
followed a few of the bug threads on PHP.net - some seem to indicate
that old bugs have been re-inroduced in PHP5 :-(

2) A lot of the socket related functions don't work on the Win32 PHP
exes (probably because the socket support isn't "pre-compiled" <??>.

3) The documentation is really far from clear - particularly with
vital differences due to the "connection-less state" of UDP.

4) For the life of me I *still* can't get fread() to work - fwrite()
works fine.

Anyway - it shows that the firewall was never the problem.

So ... thanks for persevering with me!

Adam.

=============== ===========
Here's the code:

Eventually, the script will loopo through a D/B query, but here's a
temporary loop through the 2 local test sim servers:

First the "hello" message gets sent:

$sites_array = array("192.168. 1.20", "192.168.1.126" );
foreach ($sites_array as $site_ip) {
$remote_IP = 'udp://';
$remote_IP .= $site_ip;
$portNumber = 2934;
$handle = fsockopen($remo te_IP, $portNumber, $errno, $errstr,
2);
if (!$handle) {
echo "$errno : $errstr <br/>";
}
socket_set_time out ($handle, 2);
$write = fwrite($handle, $hello);
if (!$write) {
echo "OOPS! Error writing to port: $portNumber.<br/>";
} else {
echo "Query sent to $remote_IP : $portNumber. <br/>";
};
fclose($handle) ;
Then the read of the response (note the use of socket_set_opti on() to
set the time-out etc.). Also, socket_recvfrom () seemed to work as
well.

if (!$sock=socket_ create(AF_INET, SOCK_DGRAM,SOL_ UDP)) {
echo "<b>Error:</b> Failed to create socket,
".socket_strerr or(socket_last_ error($sock))." <br>\n";
} elseif (!socket_bind($ sock,"0.0.0.0", 2934)) {
echo "<b>Error:</b> Failed to bind socket,
".socket_strerr or(socket_last_ error($sock))." <br>\n";
socket_close($s ock);
} else {
socket_set_opti on($sock,SOL_SO CKET,SO_REUSEAD DR,1);
socket_set_opti on($sock,SOL_SO CKET,SO_RCVTIME O,
array("sec"=>4, "usec"=>0)) ;
//$size=socket_re cvfrom($sock,$b uf,65535,1,$cli entIP,$clientPo rt);
$buf=@socket_re ad($sock,2048);
if ($buf===FALSE) {
//echo "<b>Error:</b> Returned false,
".socket_strerr or(socket_last_ error($sock))." <br>\n";
echo "<b>OFFLINE </b>";
} else {
echo strlen($buf) . ":" . $buf;
}
echo "<hr>";
flush();
socket_close($s ock);
}
};

=============== =======
Sep 30 '05 #13
Adam wrote:
On Mon, 26 Sep 2005 13:11:20 -0500, Jerry Stuckle wrote:

I really wish I could be more help here - but this is a problem I
haven't run into before.

Jerry - success!!!

I finally got it working - but what an ordeal!!

1) It seems that socket support in PHP is "flakey" to say the least. I
followed a few of the bug threads on PHP.net - some seem to indicate
that old bugs have been re-inroduced in PHP5 :-(

2) A lot of the socket related functions don't work on the Win32 PHP
exes (probably because the socket support isn't "pre-compiled" <??>.

3) The documentation is really far from clear - particularly with
vital differences due to the "connection-less state" of UDP.

4) For the life of me I *still* can't get fread() to work - fwrite()
works fine.

Anyway - it shows that the firewall was never the problem.

So ... thanks for persevering with me!

Adam.


Hi, Adam,

Glad to see you got it going - but that was rough!

Sorry I wasn't of much help - you did great getting it to work!

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Sep 30 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
15648
by: Sven Dzepina | last post by:
Hello people, I want to check with a php script if a port / serverservice is down. It would be great if I can check the ping time, too. But how I can realize that? Gretting from Germany.
8
4369
by: DCK | last post by:
Hello :) Into group-archive i found most e-mails, which touches PINGing. In my work i've used TELNET for testing if host is operational. Sometimes, for unknown reasons, workstation doesn't respond for PINGing. But in WinNT network, all hosts has a nbsession listening on port 139. I always use this script instead PING command (hope, will be usefull for someone :) ):
1
29999
by: gallaczmit | last post by:
Will this code give me a true view of a computer's status? All I am looking for is to see if the computer is reachable or not. My end goal is to get a list of IP addresses from a MS SQL Server, see if the IP is reachable(if yes I will assume the pc is operational), update the database with the result and generate a web page displaying the results. I am using port 135 because I have an all windows network and this port should be open...
0
7773
by: Ed | last post by:
I've attached some VB.NET code I've hacked together (some taken from MS examples & newsgroup postings) that will perform a ping or IcmpSendEcho using the icmp.dll (see this for more info: http://support.microsoft.com/default.aspx?scid=kb;en-us;170591 ). The problem I have is in order to perform a discovery/ping of an entire subnet (192.168.1.* for instance) I have to do a FOR loop to itterate through all of the addresses. That it seems...
8
18388
by: Nico Grubert | last post by:
Hi there, I could not find any "ping" Class or Handler in python (2.3.5) to ping a machine. I just need to "ping" a machine to see if its answering. What's the best way to do it? Kind regards, Nico
21
30518
by: Neel | last post by:
I am trying to "ping" a remote host in my C++/Redhat Linux code to check whether that host is connected or not. if (0 == system("ping -w 2 192.168.0.2)) But, in both cases (connected/disconnected), system call returns 0. Can someone please show what I am doing wrong? How to check the actual result of the ping status using C++ on Redhat linux ? Thanks in advance.
6
3456
by: Dave Marden | last post by:
I currently use this routine in vbscript to ping computers and get the status of ping to determine whether to try to backup a machine, I am trying to change it to work with vb2003.net I am wondering if anyone has a ping function they could share with me. I have done some searching on this but cannot find anything specifically for vb2003. Sub PingComputer If PingStatus(PCName) = "Success" Then
1
3691
by: Andy Bates | last post by:
Hi - Can't see another newsgroup to post this in; so thought I'd post here. I have a C# application that relies on multicast UDP to detect how many PCs the application is executing on concurrently. This works okay providing the port is open but fails miserably if the port is blocked by a firewall. All applications provide a server listening on the port for the ping but for some reason on the PC sending the ping irrespective of...
1
72544
by: ScottZ | last post by:
With python 2.6 and wxpython I'm trying to create a system tray icon application based around an example found here: http://codeboje.de/MailSneaker-Part-3-SystemTrayTaskBar-Icons-with-Python-and-wxPython/ The application will simply change the systray icon based on if an ip address is online or not. The ping portion looks like this: if os.name == "nt": # Windows
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9028
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.