Re: Full-Duplex communication
| From: | Vinod Panicker | Date: | Thu, 23 May 2002 10:04:49 +0000 |
| Subject: | Re: Full-Duplex communication | ||
| Groups: | php.dev php.general | ||
| Request: | Send a blank email to php-dev+get-84290@lists.php.net to get a copy of this message | ||
Hi Evan,
What you said did make sense, and complements my knowledge of sockets.
But what i'm not sure of is this - if i construct my own packet and send it across, presuming that i do have the ip address and port number of the client on which it is reading, will the client accept it as a legitimate packet?
I suspect that since the packets would be having some kind of session identifier / sequence number.
Getting the ip address and port number is no problem. I already have that getting stored on the server. But from what i know of sockets, i'm sceptical if the client will accept the packet.
Guess the only way to go ahead is to try this out.
Would someone pls pls pls write a PHP interface to libnet??
Tx,
Vinod.
On Thu, 23 May 2002 Evan Nemerson wrote :
You're right- this is getting interesting ;) http://www.packetfactory.net/libnet/manual/4.html#s4.1.5 Unless I'm mistaken, you don't need to actually hijack the socket- you merely need to write to the network. Check out section 3.1 of RFC 793. There is source and destination port- that is how they are routed. Okay anyone PLEASE correct me if i'm wrong... My understanding is a socket is an interface to the kernel. So basically, you talk to a socket, which the kernel associates with source and destination ports, and destination IP address. Thats why you can just write to a socket instead of explicitly stating all the information. The kernel then sends out then creates the packet and send it to the destination IP. libnet would allow you to bypass the socket phase, and manually create a socket. Think of a socket as a GUI for the network, and libnet is like a console ;) Hope that helps, and once again anyone PLEASE correct any inaccuracies, since I want to know. On Tuesday 21 May 2002 23:53 pm, Vinod Panicker wrote: Thanks for the reply Miguel, but here i'm not trying to implement my own multi-threaded server - exactly the reason why i'm using Apache / PHP. I could have made a listening server which is based on a multi-threaded or multi-forked model, but the time and complexities involved would be huge. Thats why I chose Apache / PHP. Now if what i'm asking for can be done, developers can easily leverage existing efficient server technologies (Apache) to build their own App servers. I know that there is no existing function in PHP that would allow it to retrieve the socket from Apache ;), all i'm asking for is a hack that would allow me to do it. I thought that i'd just as well post it on the mailing list before diving into the source code and trying to figure out for myself. No point trying to re-invent the wheel, right? Evan, that lib will allow me to create my own packets, but which socket do i send it to? Thats been the question all along. I think this is getting really interesting :) Tx, Vinod. On Wed, 22 May 2002 Miguel Cruz wrote :_________________________________________________________ Click below to visit monsterindia.com and review jobs in India or Abroad http://monsterindia.rediff.com/jobsI don't think you're going to get Apache to hand you the socket. However, you can write a program using the standalone (CGI)PHPinterpreter that will act like a server - check out http://php.net/socket_create_listen for more info. You could redirect from your standard web server to your listening PHP app running on another port. You'll then have to implement atleast asubset of the HTTP protocol in order to get browsers to talk toyou.Unfortunately, since you can't - to the best of my knowledge-fork a PHP program, you're going to have to do your own homebrewthreadingwhich will make life slightly complicated. miguel On 22 May 2002, Vinod Panicker wrote:enough.It still seems like I havent made the problem clearandI am aware of the print(), echo() and flush() functionswhatexplainthey do. It does not fit in as a solution. Let memyApacheproblem more elaborately - The client calls a PHP script, script_a.php on thewebreturnsserver, using a Keep-Alive connection. The scriptsomesendsresponse to the client which it uses. Now since theconnection isa Keep-alive, apache still has it open for reading andwriting.When the client wants to call other scripts, it justtheifrequest over the same connection. Now the thing is thattheclient,server needs to send some ASYNCHRONOUS data to thewithoutwontthe client requesting for anything, a normal PHP scriptbetheable to do it, since the script would get executed bywebIserver ONLY on a client request (coz thats the way HTTPworks).Now what i was thinking was - if i could get hold of thesocketthat is being used by apache to send data to the client,couldscripteffectively write() to it, from a C++ app or a PHP(whichecho()gets invoked from lets say another server). print(),etcopenedare functions that write to the output stream, which isascreateda result of the clients request, by the web server. I want the ability to write to a socket thats beenearlierwhen- i want to steal it from Apache, so that i can use itandhere,where i like. Functions like echo() and print() are not going to workitowill have to use write() so that i can specify the socketwhichhasthe data has to be written! Hope the problem is understood now. Now for your question - When the client wants to send data to the server, it justtoGETopen a socket connection with the web server, and issue aor aconnection,POST request! if the connection is a keep-aliveandGETit has already been created, the client just has to do aor atoPOST without the need to connect(). This mechanism, where the client frequently connects()thewayserver and checks for messages is called polling. Oneofconnectionreducing the high overhead of this is to reuse thebyimprovementusing a keep-alive connection. A still betterwouldthat itbe to remove the need for a poll altogether, by doingsomething(thats what my question is all about) on the server socanasend data asynchronously to the server. Tx, Vinod. On Wed, 22 May 2002 Bogdan Stancescu wrote :For your specific problem, I think Mr. Lemos has providedwheneverviable solution (using print() or echo() and flush()youit).need to, instead of grabbing the socket and write() toMycommunicationproblem however is how you envision solving thethetoother way around (i.e. when the CLIENT wants to send datathespecifiessomeplace.server). Bogdan Vinod Panicker wrote:Hi, Tx for your very prompt reply. Yeah, I'll post the solution as soon as I find itLet me outline the problem in more detail - Client (VC++) calls a PHP script on the server,thesomehowconnection type as Keep-Alive. The PHP script,(still aserverbig question) gets the socket on which the apachehastoreceived the client request (so that it can send datathetheclient later) and stores it in a database. Now whenever another PHP script wants to send data asynchronously to the client, it gets the socket frommessagingconnectiondatabase, and just calls a write() on it. Since theinformation,is still open (Keep-Alive), the client receives theand doesnt have to poll the server periodically. The application of this is indeed destined for awell.product, and could benefit a lot of other areas asapache.The only thing that is needed is the socket from:)Someone somewhere knows how to get this done, i'm surei'mPossibly a hack into the PHP module can get this done,openifto suggestions. Tx, Vinod. On Tue, 21 May 2002 Bogdan Stancescu wrote :Hi! I'm looking for an answer to your questions as well, soyoupostdo find a solution on other lists, could you pleaseithowhere as well? Regarding the issue, your proposal wouldn't make for full-duplex as far as I understand since I don't seethetheconnectionclient would be able to send any data on the same_after_ getting connected. What are you using on the other end of the pipe (ontheclient)? Plain HTML? Flash? Java? Something else? Bogdan Vinod Panicker wrote:Hi, We have developed a client-server application whereserversinceneeds to send asynchronous data to the client. Nowwetheare using Apache/PHP/MySQL, the client needs to pollthisserver periodically for information. I was thinking if there was some way to get aroundbasicfromsupposed toproblem. I understand that this is how things arework, but it would be just great if i could PUSH datatheApacheserver to the client, using HTTP. Since HTTP is a request/response based protocol,wouldwhat inot send any data to the client asynchronously. SowasKeep-Alivethinking was - If i tell the server to allowNowrequests,connections, and increase the timeout value and maxI would effectively have a constant TCP connection.thetoonly problem would be of sending asynchronous datatheinclient. Solution? Here goes - If there was some waywhichisi could get hold of the file descriptor(socket) thatbeingcould,used by apache to write data to the client, then ifromthea PHP script also send any data to the client usingsocketwithfunctions of PHP since i already have the socketme.theThis would mean that the client doesnt have to pollserverputclosed,for data any more... and if the connection does getanotherthe client could reconnect to the server asking forkeep-alive connection. Now I know that this is probably the wrong place tosuch abetter.query - maybe the apache list would have beenButasince I'm using PHP out here, i thought i'd give ittry.anyDoes the solution sound very outlandish? Are theresocket?pitfalls? And finally, how do i get hold of the