Reply to Re: Problem reading/writing sockets

Your name:

Reply:


Posted by Jerry Stuckle on 10/24/07 17:59

Can2002 wrote:
> I've been trying to put together an application to change channel on a
> media streaming server. The server is able to issue IR commands to
> its attached equipment using LIRC, with commands being issued by a
> socket connection to TCP/8765.
>
> I put together a basic Python app that issued a command, which worked
> fine. I wanted to create a fairly simple web interface and so set
> about producing a similar simple PHP application. I've had limited
> success so far, with the media server rejecting the connections.
> Unfortunately I have limited access to the OS of the media server - I
> just know that it recognises the commands from the Python app and
> rejects the PHP one. I need to submit the following string:
>
> SEND_ONCE pace_stb_5 rm_power
>
> My PHP app (with all error checking removed) is as follows:
>
> <?php
> error_reporting(E_ALL);
> echo "<h2>TCP/IP Connection</h2>\n";
> $service_port = '8765';
> $address = '192.168.1.100';
> $socket = socket_create(AF_INET, SOCK_STREAM, 0);
> $result = socket_connect($socket, $address, $service_port);
> $out = '';
>
> socket_send($socket, 'SEND_ONCE pace_stb_5 rm_power\n',
> strlen('SEND_ONCE pace_stb_5 rm_power\n'));
> echo $result . "OK<br />";
>
> $out = socket_read($socket, 1024);
> echo $out;
>
> socket_close($socket);
> ?>
>
> In case it's of use, my Python application is:
>
> #!/usr/bin/python
> import socket,string
>
> def send_ir(host, port, command):
>
> exterity=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
> exterity.connect((host, port))
> exterity.send(command+"\n")
>
> while 1:
> response = exterity.recv(1024)
> if response.split('\n')[-2] == "END":
> return response.split('\n')[1]
> break
> exterity-socket.close()
>
> HOST = '192.168.1.100'
> PORT = 8765
>
> status = send_ir(HOST, PORT, 'SEND_ONCE pace_stb_5 rm_power')
> print status
>
> On the face of it it seems as though both apps are sending the same
> string; however I'm wondering if they're submitting the strings in a
> different way. Apologies if any of the above is vague; I'll happily
> provide any additional information if needed!
>
> Thanks in advance,
> Chris
>
>

socket_send($socket, 'SEND_ONCE pace_stb_5 rm_power\n',

You have the string in single quotes, so PHP sends the characters
backslash and en, instead of the newline character you want.

Try pulling the string in double quotes (in both places).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация