Socket Issue with using a duplicated active socket.

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
jdredd
Forum Newbie
Posts: 5
Joined: Thu Jun 18, 2009 12:34 pm

Socket Issue with using a duplicated active socket.

Post by jdredd »

I have a telnet based application that runs, and need to add support for PHP to run. So I already have the connection / Socket created and going, and socket duplicated before i createprocess run php.

I just run c:\php\php.exe Test.PHP 12345
12345 being the socket handle

Having issues finding out to just read/write from the socket. I don't need to create/bind/ect.. my main app does that already.
This works in my other child apps that are not PHP based.

Been looking around but only find examples for making a PHP that will create/bind/listen .. not just "inherit" the socket handle i want to pass it.
Last edited by jdredd on Thu Jun 18, 2009 3:22 pm, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Socket Issue..

Post by requinix »

php.exe will inherit the socket but your PHP script will not.

PHP deals with sockets using resources. You need a resource - like the one returned by socket_create - to do anything. You still have to open the socket in your code.
jdredd
Forum Newbie
Posts: 5
Joined: Thu Jun 18, 2009 12:34 pm

Re: Socket Issue..

Post by jdredd »

Thats what I figured, but I can't get how to create the resource and have it use the socket handle ID that passed.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Socket Issue with using a duplicated active socket.

Post by Weirdan »

You could dup2() the socket handle to STDIN/STDOUT before executing php binary. For those fds PHP automatically creates resources, accessible as STDIN/STDOUT constants from php userland code. I guess inetd does something like this.
jdredd
Forum Newbie
Posts: 5
Joined: Thu Jun 18, 2009 12:34 pm

Re: Socket Issue with using a duplicated active socket.

Post by jdredd »

Dup2 ?

I am using Delphi to create a console application that is telnet based. Being able to use PHP to be ran and display the output back to the end user would be great. Spawning other non php apps that have i have from it that use the passed socket handle work fine, but they are written in freepascal and have direct winsock access easily.

Still trying out some things but so far no luck, just missing 1 thing basically to bring it all together.

Steven
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Socket Issue with using a duplicated active socket.

Post by Weirdan »

jdredd wrote:Dup2 ?
Oh, dup2() is a unix api call. I didn't realize you were using windows. From what I heard, under windows you can use dio functions to access open file descriptors by their numbers, but then again, Winsock handles are not files. There's a example in MSDN that shows how to achieve on windows what dup2 does on unix platforms: http://support.microsoft.com/default.as ... -us;190351
jdredd
Forum Newbie
Posts: 5
Joined: Thu Jun 18, 2009 12:34 pm

Re: Socket Issue with using a duplicated active socket.

Post by jdredd »

Ok... i was able to create in/out pipes in my Delphi application. So when someone telnets in.. they can use the telnet service
as usual then i have a command they can run, and it will execute PHP.EXE to run the .php file. It will pipe out to the telnet connection and they can input/output like it was nothing. I have the script doing out ANSI graphics to make it pretty.
Now my next thing is, is how to get ANSI graphics to work on the "Server" side. On the server side, you see the ansi chars and all.

Can PHP do any color changing modes in command line? If so, ill just port over my ansi parser to PHP and all my color output commands, ect. thats if PHP can do that.

Anyone know a way to get XP cmd.exe to do ansi? i can modify the config.NT file and set it to dosmode and ansi.sys , but it wont work with the php.exe as Dosmode wont run win32 apps.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Socket Issue with using a duplicated active socket.

Post by Weirdan »

jdredd wrote:Can PHP do any color changing modes in command line?
You just output certain sequences of bytes. Actual coloring must be supported by a terminal application. The cmd.exe does not parse ansi escapes, so you will need another wrapper program, like ANSICON
jdredd
Forum Newbie
Posts: 5
Joined: Thu Jun 18, 2009 12:34 pm

Re: Socket Issue with using a duplicated active socket.

Post by jdredd »

I got the localside ansi stuff taken care of.

Now that Im this far, is there a way to write new input routines?

fread / fget ... i can sepcify the length of the return.. but it doesn't limit how much they can type in initially.

I would love to have a routine that could like

getinput($input,20);

and would only allow them to type 20 chars max. but that would require to read their input char by char and decide when to
stop.
Post Reply