Code Monkey home page Code Monkey logo

Comments (10)

paragi avatar paragi commented on August 17, 2024

I would start by hardcoding the address for a test. Are you sure that localhost is translated?

from php-websocket-client.

daniel89fg avatar daniel89fg commented on August 17, 2024

Yes, my connection from javascripts is (localhost:9235), I can connect and send messages to the server and I receive the response without problem.

What I can't get is to connect the client from php to the same server.

from php-websocket-client.

Trismegiste avatar Trismegiste commented on August 17, 2024

'localhost?idphonenumber='... is not a valid host.

Query parameters ('?id...) should go into the $path parameter in the constructor:

public function __construct(string $host = '', int $port = 80, $headers = '', &$error_string = '', int $timeout = 10, bool $ssl = false, bool $persistant = false, string $path = '/', $context = null)

That differs from the WebSocket javascript class which takes a full URL (host + query parameters)

from php-websocket-client.

daniel89fg avatar daniel89fg commented on August 17, 2024

With or without parameters, it does not make the connection. I am using docker and port 9235 is open.

from php-websocket-client.

Trismegiste avatar Trismegiste commented on August 17, 2024

Ratchet server runs in the same docker container as the php script client ?
If not, what is the network_mode ? host ?

I have a project which runs on docker with Ratchet with PHP client and javascript client (with text & binary socket)
https://github.com/Trismegiste/eclipse-wiki

from php-websocket-client.

paragi avatar paragi commented on August 17, 2024

Host and path is not necessarily the same thing.
You want to specify the path, not the host.

The implementation might be a little clumsy - I don't remember why host is not a part of path...?

Try something like this:

path: '127.0.0.1?idphonenumber=12345678'

( 'localhost' is not translated to 127.0.0.1 )

from php-websocket-client.

daniel89fg avatar daniel89fg commented on August 17, 2024

The Ratchet server is in a Docker container called "wasocket".

And the chat container for the client in a separate one called "facturascripts".

The network of both containers is not set, from what I understand it will be the default.

from php-websocket-client.

daniel89fg avatar daniel89fg commented on August 17, 2024

I still can't get it to work

try {
            $headers = '';
            $error_string = '';
            $sp = new \Paragi\PhpWebsocket\Client(
                'localhost',
                9235,
                $headers,
                $error_string,
            10,
            false,
            false,
                '127.0.0.1?idphonenumber=' . $phone->idphonenumber);
            $sp->write("hello server");
            echo "Server responded with: " . $sp->read();
        } catch (\Paragi\PhpWebsocket\ConnectionException $e) {
            echo "Something gets wrong " . $e->getMessage();
        }

from php-websocket-client.

daniel89fg avatar daniel89fg commented on August 17, 2024

This is my docker-compose.yml

version: '3'

services:

  facturascripts:
    container_name: facturascripts
    build: ./php7.4
    restart: always
    ports:
      - 80:80
    volumes:
      - ./facturascripts:/var/www/html
      
  wasocket:
    build: ./php7.4-wasocket
    container_name: wasocket
    ports:
      - 9235:9235
    volumes:
      - ./wasocket:/var/www
      
networks:
  proxy:
    external: true

from php-websocket-client.

daniel89fg avatar daniel89fg commented on August 17, 2024

I got it, it connects now. Thanks for the support and help.

from php-websocket-client.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.