tcp send

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jorgeng
Forum Commoner
Posts: 43
Joined: Mon Aug 04, 2008 8:05 am

tcp send

Post by jorgeng »

I want to send data to external computer, ip 99.99.99.99 on port 9999, i think this work.
I will read data on port 9998, think this code work.
How does i get data into a variable to read the values on port 9998?
:roll:

<?php
$fp = fsockopen("tcp://99.99.99.99", 9999, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />\n";
} else {
$szData = '<?xml version="1.0" encoding="Windows-1252" ?> print("XML-sträng skickad på port 9999");

// Skickar frågor på port 9998.
$fp = fsockopen("tcp://99.99.99.99", 9998, $errno, $errstr);
$szData2 = 'i;R';
fwrite($fp, $szData2 );
print $szData2;
print("Fråge-sträng skickad på port 9998");

// fwrite($fp, "\n");
// echo fread($fp, 26);
fclose($fp);
}
?>
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: tcp send

Post by panic! »

How about using a query string over http and using file_get_contents?

Code: Select all

 
// url encode $szData first
 
file_get_contents("http://99.99.99.99/listener.php?data=".$szData);
 
then on server 99.99.99.99 make a script called listener.php

Code: Select all

 
 
$data=$_GET['data'];
 
//decode and use the data.
 
 
jorgeng
Forum Commoner
Posts: 43
Joined: Mon Aug 04, 2008 8:05 am

Re: tcp send

Post by jorgeng »

Thanks, but i can't handle the communcation since the remote server is another company which i can't control.
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: tcp send

Post by panic! »

Sorry I thought because you said 'how do I read values on port 9999?' You were asking how to receive the script on the other end.

Could you rephrase the question?
jorgeng
Forum Commoner
Posts: 43
Joined: Mon Aug 04, 2008 8:05 am

Re: tcp send

Post by jorgeng »

I send data at ip 99.99.99.99 port 9999 - fake adress, i can't publish the real ip

i send data at same ip-adress and a new port 9998 which is the port where i shall get
the response from the other company.

My problem is how do i handle response from ip 9998, i think by a webserver at my
own physical pc which listen for incoming data, how do i program this?

:roll:
jorgeng
Forum Commoner
Posts: 43
Joined: Mon Aug 04, 2008 8:05 am

Re: tcp send

Post by jorgeng »

I don't know, this is a php forum?, hasn't anyone done a reading to own webserver and
get me a code example?
:cry:
Post Reply