alin19 Posted September 5, 2008 Share Posted September 5, 2008 i have a java aplication that connects to a local server on a 9191 and output an xml mesage, i't a java aplication,can i connect to that using php Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/ Share on other sites More sharing options...
alin19 Posted September 5, 2008 Author Share Posted September 5, 2008 is this what i must use? :http://www.php.net/manual/en/function.hw-pconnect.php Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634374 Share on other sites More sharing options...
alin19 Posted September 5, 2008 Author Share Posted September 5, 2008 i have found this with google: it is this good? THE PHP SOCKET SERVER (run on browser for the moment - daemon later when sorted!) <?php // set some variables $host = "my ip address"; $port = 1234; // don't timeout! set_time_limit(0); // create socket $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n"); // bind socket to port $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n"); // start listening for connections $result = socket_listen($socket, 5) or die("Could not set up socketlistener\n"); // accept incoming connections // spawn another socket to handle communication $spawn = socket_accept($socket) or die("Could not accept incomingconnection\n"); // read client input $input = socket_read($spawn, 1024) or die("Could not read input\n"); $output = "Hello"."\0"; socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n"); */ // close sockets socket_close($spawn); socket_close($socket); ?> Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634394 Share on other sites More sharing options...
alin19 Posted September 5, 2008 Author Share Posted September 5, 2008 nobody can help me? Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634445 Share on other sites More sharing options...
trq Posted September 5, 2008 Share Posted September 5, 2008 Sorry, but you seem to have failed to actually ask a question. What exactly are you trying to do, and what is it that isn't working for you? Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634470 Share on other sites More sharing options...
alin19 Posted September 5, 2008 Author Share Posted September 5, 2008 i have a server and i must conect to it, i know how to do this with java, how can i do it with php? host: "127.0.0.1" port: "9191" Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634477 Share on other sites More sharing options...
trq Posted September 5, 2008 Share Posted September 5, 2008 What protocol? Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634480 Share on other sites More sharing options...
alin19 Posted September 5, 2008 Author Share Posted September 5, 2008 try{ kin = new BufferedReader(new InputStreamReader(System.in)); s = new Socket("127.0.0.1",9191); dos = new DataOutputStream(s.getOutputStream()); dis = new DataInputStream(s.getInputStream()); System.out.print(dis.readUTF());//connected System.out.print(dis.readUTF());//user dos.writeUTF(kin.readLine());dos.flush(); System.out.print(dis.readUTF());//pass dos.writeUTF(kin.readLine());dos.flush(); String z=""; BufferedWriter out = new BufferedWriter(fstream); while (true){ System.out.print(dis.readUTF());//xml msl } }catch(Exception e){ e.printStackTrace(); } i don't know exactly what it is using, but with this is working, i need to do something like this but in php and i don't know from where to start i will find out in a few minutes what protocol it is Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634486 Share on other sites More sharing options...
alin19 Posted September 5, 2008 Author Share Posted September 5, 2008 tcp is the protocol that is used Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634496 Share on other sites More sharing options...
trq Posted September 5, 2008 Share Posted September 5, 2008 tcp is the protocol that is used While tcp is a protocol, it is a much lower level prototocol than is typically used for any form of transmission. For instance, http (what your using to view this website) is built on top of TCP, but it would be rediculously complex to try and request a webpage via TCP allone. In order for this connection to take place, what does the server expect in its request and what do you expect in its response? Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634499 Share on other sites More sharing options...
alin19 Posted September 5, 2008 Author Share Posted September 5, 2008 i haven't used connection to server, so sorry if i don't explain so well, the connection is only local and it is made with a java serve not php, after the connection is made it outputs: username, and wait for a username, the password and wait for the password, after that only outputs data in this format: <bmfm t='222'> <info><label>503</label><value>DESIF5</value></info> <info><label>504</label><value>DEC08</value></info> <info><label>620</label><value>Call</value></info> <info><label>630</label><value>3.6</value></info> <info><label>510</label><value>0.05</value></info> <info><label>511</label><value>0.0</value></info> <info><label>635</label><value>0.0</value></info> <info><label>520</label><value>0.0</value></info> <info><label>530</label><value>0.0</value></info> <info><label>531</label><value>0.0</value></info> <info><label>525</label><value>0</value></info> <info><label>540</label><value>0</value></info> <info><label>542</label><value>0</value></info> <info><label>550</label><value>0</value></info> </bmfm> Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634505 Share on other sites More sharing options...
alin19 Posted September 5, 2008 Author Share Posted September 5, 2008 i will use java, i see it can't be done with php, Link to comment https://forums.phpfreaks.com/topic/122838-solved-connecting-to-a-server/#findComment-634565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.