/    Sign up×
Community /Pin to ProfileBookmark

connect to the TCP/IP socket feed

im doing some basic XML parsing for a small client, but ran into a dead before i even got started trying to get the XML data.

The instructions i was given are as follows:

[QUOTE]

Here is the connection information, which you will need to connect to the TCP/IP socket feed.

IP Address: *.*.*.*
Port: 4500 (XML feed) or 4200 (ASCII feed)
Username/password: **** / ****

[/QUOTE]

also a perl script was included that does exactly what i need (but not perl)

[CODE]
use IO::Socket;
use strict;
#Replace xxxxx with your username
my $login = “*****r”;
#Replace xxxxx with your password
my $pword = “*****r”;
my $port = 4500;
my $server = ‘*.*.*.*’; #replace the IP address here
my ($data,$socket);
$socket = IO::Socket::INET->new(
PeerAddr => $server,
Proto => ‘tcp’,
PeerPort => $port );
[/CODE]

the problem is i am unable to mimic the code in PHP

any help in the right direction would be a great help

-aPeg

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 03.2009 — Have you looked at [url=http://php.net/fsockopen]fsockopen[/url]() (including the users' notes)?
Copy linkTweet thisAlerts:
@apegauthorDec 03.2009 — My Google searching keeps bringing me back to that, I have given the page a good read but can’t seem to figure out how to enter a username/password.

If I try the basic code:
[CODE]$fp = fsockopen("udp://127.0.0.1", 13, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />n";
} else {
fwrite($fp, "n");
echo fread($fp, 26);
fclose($fp);
}[/CODE]


The result I get is one line:

Username:

Another user farther down provided a user/pass example to get UIDL, but im not able to get it working (im not expert when it comes to this)

[CODE]$fp = fsockopen($host, 110, $errno, $errstr, 5);
if ($fp > 0) {
fread($fp,1024);
fputs($fp, "USER $userrn");
fread($fp,1024);
fputs($fp, "PASS $passrn");
fread($fp,1024);
fputs($fp, "UIDLrn");
fgets($fp,1024);
do {
$line = rtrim(fgets($fp, 1024));
if ($line == '.') break;
list(, $UIDL) = split(' ', $line, 2);
echo $UIDL;
} while ($line != '.');

fputs($fp, "QUITrn");
}
fclose($fp);[/CODE]


Im running out of tangents to read up on... ideas?

Thanks

-aPeG
Copy linkTweet thisAlerts:
@apegauthorDec 03.2009 — I was able to figure it out using fsockopen, just took some time to firgure it all out, thanks NogDog

[CODE]
$fp = fsockopen("IP_ADDRESS_HERE", PORT_HERE, $errno, $errstr);
if (!$fp) echo "ERROR: $errno - $errstr<br />n";
} else {
fread($fp,26);
fputs($fp, "USERNAME_HERErn");
fread($fp,26);
fputs($fp, "PASSWORD_HERErn");
fread($fp, 1024);
}
[/CODE]



that last 1024 may need to be increased depending on the size of your XML file

-aPeG
Copy linkTweet thisAlerts:
@NogDogDec 03.2009 — Glad you figured it out. I've not had cause to use fsockopen() myself yet, but was pretty sure it could do what you needed.
×

Success!

Help @apeg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...