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!
Its been a while i have'nt worked on my project.Back here again.
I've written a small program where it requests the user to input some text through an HTML form and this creates a connection to the other pc in the network via the ip-address i mentioned in my code.The user i/p is sent from my machine to the other machine and return the value from the other machine(the same string but in reversed order) and is displayed to the user on an HTML page.
Errors: I dont get any text in the reverse order.
Windows NT is the environment.
<html>
<head
</head>
<body>
<?php
//Form not yet submitted
if (!$submit)
{
?>
<form action="<? echo $PHP_SELF; ?>" method="post">
Enter some text:<br>
<input type="Text" name="message" size="15"><input type="submit" name="submit" value="send">
</form>
<?
}
else{
//form submitted
//Where is the socket server?
$host="heres the ip-address of the machine I'm connecting";
$port = portno;
//create a socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die ("could not create socket\n" );
//connect to server
$result = socket_connect($socket, $host, $port) or die ("could not connect to server\n" );
socket_read ($socket, 1024) or die ("could not read server response\n" );
//send string to server
socket_write($socket, $message. strlen($message)) or die ("could not send data to server\n" );
//get server response
socket_read ($socket, 1024) or die ("could not read server response\n" );
//end session
socket_write($socket, "END", 3) or die ("could not end session\n" );
//close socket
socket_close($socket);
//clean up result
$result = trim($result);
$result = substr($result, 0, strlen($result)-1);
//print result to browser
?>
Server said: <b><? echo $result; ?></b>
<?
}
?>
</body>
</html>
Report Post | IP: Logged
a client socket always connect to a server socket, so the machine you connect to must accept socket connections, "a server".. Just like a web server accepts connections on port 80 for http and FTP servers accepts on port 21 etc..
Your client is the plug - the server is the receptacle -- socket
OK, Heres the explanation of what I'm trying to do.
First, I would like to establich the connection between 2 computers in the network, IP-address being the input.
In one machine, I'll install Matlab software(This software is used for simulation purpose or for some mathematical calculations).Once, I'm connected, I would like to issue a command or send a file or a variable in order to run those scripts.Once, the scripts are executed, i would like to ge those results back to my computer.This is what I'm trying to do.
I've read the file system and sockets in the PHP manual and got some idea.In-order to communicate, I know that i need a service running in the other machine all the time.How can i write this service program or is it available on the web for free??
If somebody can guide me, i can give a try.
I would say that your best approach would be using a web server on the other machine ,l ike apache (free) with php, then do not use sockets but standard http get or post...
e.g. on the "service" machine make a script that uses the parameteres in the url to perform calulations and return values..
So a simple client/server could be like