473,378 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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_flush();

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

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

echo "connected\n";

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

Any suggestions ? Thanks in advance.

Fred.
Oct 3 '05 #1
2 2230
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_flush();

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

if (($ret = socket_connect($sock, $address, $port)) < 0)
{
die("socket_connect() 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
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...
4
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...
4
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...
0
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...
1
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....
3
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...
0
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...
5
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...
2
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.