473,569 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP socket

Hello,

I need to check if a user has properly open his port on his computer. He
will call a script specifing the port he want to use and the script will
have to check if he can open a socket on the IP:Port.
Here is a what I have tried but it doesn't work, even if the port is
properly open :

-----------------------------Script ------------------
<?php
ob_implicit_flu sh();

if (($sock = socket_create(A F_INET, SOCK_STREAM, SOL_TCP)) < 0)
{
die("socket_cre ate() failed : " . socket_strerror ($sock) . "\n");
}

if (($ret = socket_connect( $sock, $address, $port)) < 0)
{
die("socket_con nect() failed : raison : " . socket_strerror ($ret) .
"\n");
}

echo "connected\ n";

socket_close($s ock);
?>
-------------------------End Script ---------------------

Any suggestions ? Thanks in advance.

Fred.
Oct 3 '05 #1
2 2238
Here is a what I have tried but it doesn't work, even if the port is
properly open :


What doesn't work? What does your browser display? What are the error
messages? What OS is your server running? What version? What version of
PHP are you using? So many questions, so little time...

---
Steve

Oct 4 '05 #2
On Mon, 3 Oct 2005 23:08:23 +0200, Boniface Frederic wrote:
Hello,

I need to check if a user has properly open his port on his computer. He
will call a script specifing the port he want to use and the script will
have to check if he can open a socket on the IP:Port.
Here is a what I have tried but it doesn't work, even if the port is
properly open :

-----------------------------Script ------------------
<?php
ob_implicit_fl ush();

if (($sock = socket_create(A F_INET, SOCK_STREAM, SOL_TCP)) < 0)
{
die("socket_cre ate() failed : " . socket_strerror ($sock) . "\n");
}

if (($ret = socket_connect( $sock, $address, $port)) < 0)
{
die("socket_con nect() failed : raison : " . socket_strerror ($ret) .
"\n");
}

echo "connected\ n";

socket_close($ sock);
?>
-------------------------End Script ---------------------

Any suggestions ? Thanks in advance.


I've been messing with just this lately - see the thread "Ping+Port
Routine". It's not that old.

In short, it's a nightmare!

1) Depends on which build of PHP - whether it was compiled with socket
support.

2) OS Dependent. Many socket functions don't appear to work on a Win32
setup.

3) Contrary to what it says on the PHP bugtracker, I think many of the
socket routines still have bugs. Some even appear to have been
re-introduced in PHP5.

4) Check whether a firewall is blocking things.

5) Set up a port "sniffer" (Ethereal or suchlike) to see whether
packets are a actually leaving/arriving (though a firewall can still
block these).

6) I found that a socket sometimes gets "blocked" with an error - even
when the [code] error has been fixed. Try it with another port (that
you know is open). After a time, I've found I can re-use the original
connection. There must be a timeout somewhere.

Adam.
Oct 4 '05 #3

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

Similar topics

8
9271
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the python wrapper module for sockets, and found that the close command doesn't actually call the underlying close! this didn't seem right, so i added...
4
8712
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects the child socket remains in the CLOSE_WAIT state. Anyone have any idea what's missing? ----------------------------- Socket Code...
4
18097
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed as I find appropriate. I am using the socket asynchronously by calling the BeingSend and BeginReceive calls. I would like to be able to call...
0
4660
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a number of different types of data coming in. I have a databuffer for each type of data coming in.
1
10053
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol. This program can perform 5 options from a menu on your POP3 mail by logging in with the correct POP3 server along with a user name and password that you...
3
4277
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the receiver is running within Process1. If I move the receiver into Process2 then its fast. Please can someone explain.
0
3151
by: Buddy Home | last post by:
There is two examples of code. Example 1. Send and Receive within the same process. Put this code in a console app called SendAndReceive and run the code. using System; using System.Collections.Generic; using System.Net; using System.Net.Sockets; using System.Runtime.Serialization.Formatters.Binary;
5
12760
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for more incoming connections and does the BeginAccpet() again. It does an infinite loop this way. My question is: What is the best way to stop this? ...
2
16131
by: kashifjawed | last post by:
I'm developing a c# asynchronous socket application for tranfering file or large data from client to server and server to client as well in chunks. Application sometimes transfer file from client to server and sometimes not, because connection betwenn client and server closed Abrupt. I cannot understand why connection between client and...
1
3356
Airslash
by: Airslash | last post by:
Hello, The problem is that my server is not receiving data. The code below are the various classes I designed around sockets. It will be big... I have run the code with the debugger, and I see in the debug output that the client connects to the server, the events get fired and the disconnect event gets fired as well. I get confirmation...
0
7703
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...
0
7619
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...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
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...
0
3662
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...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.