viabtc / viabtc_exchange_server

A trading engine with high-speed performance and real-time notification
MIT License
2.68k stars 1.49k forks source link

Socket connection example #126

Open hkmohit opened 6 years ago

hkmohit commented 6 years ago

Hello, I have been trying to access data via websocket using localhost. I have forwarded the port to my local in order to check the same. I am using this as a docker setup. Default port given for same is 18091 when I try to access anything via ws I am not able to see any activity in logs. If anyone has got any example of how it can be implemented it would be great. Docs have no such example to implement the same.

Thanks in advance.

yunhui0501 commented 6 years ago

你的websocket建立通信没有?你已经修改了CONFIG.JSON的配置吗?

ohld commented 6 years ago

I'm also interested in websocket usage example! I'll implement it in my python API wrapper. Not you can find there only REST API.

Junbin-Hao commented 6 years ago

I was able to setup but got connection timout error in nginx log. Anyone can help? thanks a lot.

ohld commented 6 years ago

@Junbin-Hao Can you please send here steps you've made to reproduce the issue? Anyway no-one can help you

Junbin-Hao commented 6 years ago

@ohld I added this in nginx configuration file, it looks does not work server { listen 8090; location / { proxy_pass http://localhost:8091; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";

        proxy_set_header Origin *;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
    }
}

nginx error logs: 2018/08/07 16:45:53 [error] 520#520: 600 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 121.69.7.78, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8091/", host: "47.100.43.5:8090" 2018/08/07 16:46:42 [error] 520#520: 596 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 121.69.7.78, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8091/", host: "47.100.43.5:8090" 2018/08/07 16:46:53 [error] 520#520: 600 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 121.69.7.78, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8091/", host: "47.100.43.5:8090" 2018/08/07 16:51:30 [error] 520#520: 611 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 121.69.7.78, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8091/", host: "47.100.43.5:8090" 2018/08/07 16:52:30 [error] 520#520: 611 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 121.69.7.78, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8091/", host: "47.100.43.5:8090" 2018/08/07 16:52:42 [error] 520#520: 614 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 121.69.7.78, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8091/", host: "47.100.43.5:8090" 2018/08/07 16:52:52 [error] 520#520: *616 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 121.69.7.78, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8091/", host: "47.100.43.5:8090"

yunhui0501 commented 6 years ago

@Junbin-Hao http {

 map $http_upgrade $connection_upgrade { 
 default upgrade; 
 ” close; 
} 

upstream websocket {
    server 192.168.0.77:9000;
    #server 192.168.0.78:9000;
}    

server {
    listen 8888;
    location / {
        proxy_pass http://websocket;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_http_version 1.1;
        proxy_redirect    off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

}

Junbin-Hao commented 6 years ago

@yunhui0501 The port of websocket is 9000?

yunhui0501 commented 6 years ago

@Junbin-Hao 我设置的是9000,你可以自己设置端口

henrytom1703 commented 5 years ago

Hi guys I'm using docker of @ohld to build a server ( https://github.com/testnet-exchange/viabtc_exchange_server) But I have an issues Websocket will lost connection (not working or don't receives any message ) after 30s (After 30s user didn't interact) nginx config

 map $http_upgrade $connection_upgrade { 
 default upgrade; 
 ” close; 
} 

upstream websocket {
    server http://localhost:8090;
}    

server {
    listen 8888;
    location / {
        proxy_pass http://websocket;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_http_version 1.1;
        proxy_redirect    off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

    }
}

Anyone can help me? Thanks

lawrence296 commented 5 years ago

One way is to keep the connection alive by sending "ping" messages to the server regularly.

wh0am111 commented 4 years ago

Cross domain configuration of websocket,anyone know?