Jump to content

[SOLVED] connecting to a server


alin19

Recommended Posts

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);

?>

 

 

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

 

 

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?

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.