Giter VIP home page Giter VIP logo

Comments (9)

sacOO7 avatar sacOO7 commented on June 30, 2024 1

from socketcluster-client-java.

sacOO7 avatar sacOO7 commented on June 30, 2024

Hey I think I can point you to the example from where you can replicate for the same.


import logging
from socketclusterclient import Socketcluster
logging.basicConfig(format="%s(levelname)s:%(message)s", level=logging.DEBUG)

import json

api_credentials = json.loads('{}')
api_credentials["apiKey"]="xxx"
api_credentials["apiSecret"]="xxx"


def your_code_starts_here(socket):
    ###Code for subscription
    socket.subscribe('TRADE-OK--BTC--CNY')                 # Channel to be subscribed

    def channelmessage(key, data):                         # Messages will be received here
        print ("\n\n\nGot data "+json.dumps(data, sort_keys=True)+" from channel "+key)

    socket.onchannel('TRADE-OK--BTC--CNY', channelmessage) # This is used for watching messages over channel
    
    ###Code for emit

    def ack(eventname, error, data):
        print ("\n\n\nGot ack data " + json.dumps(data, sort_keys=True) + " and eventname is " + eventname)    
    
    socket.emitack("exchanges",None, ack)  

    socket.emitack("channels", "OK", ack)  
      


def onconnect(socket):
    logging.info("on connect got called")

def ondisconnect(socket):
    logging.info("on disconnect got called")

def onConnectError(socket, error):
    logging.info("On connect error got called")

def onSetAuthentication(socket, token):
    logging.info("Token received " + token)
    socket.setAuthtoken(token)

def onAuthentication(socket, isauthenticated):
    logging.info("Authenticated is " + str(isauthenticated))
    def ack(eventname, error, data):
        print ("token is "+ json.dumps(data, sort_keys=True))
        your_code_starts_here(socket);

    socket.emitack("auth", api_credentials, ack)

if __name__ == "__main__":
    socket = Socketcluster.socket("wss://sc-02.coinigy.com/socketcluster/")
    socket.setBasicListener(onconnect, ondisconnect, onConnectError)
    socket.setAuthenticationListener(onSetAuthentication, onAuthentication)
    socket.setreconnection(False)
    socket.connect()

This is a logic for python client, just replicate it in java. If there is still problem, let me know about it.

from socketcluster-client-java.

acz123454 avatar acz123454 commented on June 30, 2024

from socketcluster-client-java.

acz123454 avatar acz123454 commented on June 30, 2024

from socketcluster-client-java.

acz123454 avatar acz123454 commented on June 30, 2024

Did method as write below should be automatically called while connect?

public void onSetAuthToken(String token, Socket socket) {
socket.setAuthToken(token);
}

When I debugging, the method is not called.

from socketcluster-client-java.

acz123454 avatar acz123454 commented on June 30, 2024

That is it! :D It works, it was problem in sending String , not Json object :)

Thanks!

from socketcluster-client-java.

sacOO7 avatar sacOO7 commented on June 30, 2024

Ohk I'm closing the issue :). Please star and fork the repo. if you like it 👍 .

from socketcluster-client-java.

panekzogen avatar panekzogen commented on June 30, 2024

Hi,
I'm using java sample written above and always get exception:

Got connect error com.neovisionaries.ws.client.WebSocketException: Failed to send an opening handshake request to the server: Received fatal alert: handshake_failure

Does it sample really work now?

from socketcluster-client-java.

panekzogen avatar panekzogen commented on June 30, 2024

I found solution for it.
I used sample with java 7. But java 7 set old TLSv1 by default. And it caused this problem.
If you set TLS to version v1.2 it will work.

from socketcluster-client-java.

Related Issues (20)

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.