Welcome, Guest. Please login or register.

Login with username, password and session length
Pages: [1]   Go Down
Print
Author Topic: How have you implemented filePro Sockets?  (Read 5968 times)
0 Members and 1 Guest are viewing this topic.
Lauren
Administrator

Posts: 176


View Profile
« on: November 12, 2007, 06:35:30 PM »

I'm wondering if anyone would like to share how you have implemented filePro Sockets.

Do you have any code samples you can share?

Ideas you've had on how to use filePro Sockets, but haven't tried yet?

I'm trying to see what kind of resources we can build for those new to using sockets.

Thanks!!  Grin
Logged
syntencoist
Member

Posts: 7


View Profile
« Reply #1 on: November 25, 2011, 09:01:20 PM »

I know this thread has long since died, however I figure an answer would be helpful to those who are looking for FilePro port examples.

I didn't really like the FilePro socket control, it seems to be very limiting. However you can easily write out information to files using the jsfile command and port the information over using some very simple PHP. This script was made under a machine running PHP 5.3

jsfile :tx "Hello World"
system "/bin/php /library/port.php"

$argv[1] is the filename and it sends the file to the host and then reads the socket connection for the response given the timeout period.

Code:
<?php 
date_default_timezone_set
("America/Phoenix");
$filepath="/portfiles";
function 
res_file($trans$sent) {
global $filepath;
file_put_contents($filepath.$trans.".res"$sentLOCK_EX);
}
function 
res_err($trans$msg) {
global $filepath;
file_put_contents($filepath.$trans."err.res"date("mdy:His")." - ".$msg."\n"FILE_APPEND LOCK_EX);
exit();
}
$init_micro=microtime(true);
$eof=true;
$host="192.168.1.101";
$port="1022";
$timeout=30;
$infile=(isset($argv[1]))?$argv[1]:"";
if (
preg_match("/close/"$infile)){
$timeout=600;
}
$contents="";
if (
$infile == ""){
res_err ("""Error: Need one arguements.");
} else {
try {
$contents=file_get_contents($filepath.$infile.".req");
$contents=trim($contents)."";
} catch(Exception $e) {
res_err ($infile"Error: Getting file exception.");
}
}
//echo "\nAttempting to connect...";
$sk=fsockopen($host,$port,$errnum,$errstr,$timeout);
stream_set_blocking ($skfalse);
if (!
is_resource($sk)) {
res_err ($infile"Error: connection fail: ".$errnum." ".$errstr);
} else {
//echo "\nConnected; Sending Data...";
fwrite($sk$contents);
$dati="";
while (!feof($sk) && $eof ) {
if ((microtime(true) - $init_micro) > 15000){
res_err ($infile"Error: Socket Communication longer than default setting allowed.");
}
$dati.= fread ($sk4096);
$eof=(preg_match("/99,\"\"/i"$dati))?false:true;
//echo "\nConnected; Getting Data...".$dati;
}
}
//echo "\nConnected; Closing Socket...";
fclose($sk);
//echo "\nConnected; Writing file...";
res_file($infile$dati);
//echo($dati);
?>

Logged
Pages: [1]   Go Up
Print
Jump to:  

Valid XHTML 1.0! Powered by SMF 1.1.15 | SMF © 2011, Simple Machines | Massive Blue Theme By Cadosoas Valid CSS!