From 5f50fe7a4a6218bedf78333d751b57166932464a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 27 Jan 2015 12:28:58 -0600 Subject: [PATCH] Update CLI to use new Websocket RPC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use “wsport” flag to change default port --- cmd/ethereum/flags.go | 2 ++ cmd/ethereum/main.go | 2 +- cmd/utils/cmd.go | 16 ++++++++++++---- eth/backend.go | 4 ++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index f829744dc..e0fbbb008 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -41,6 +41,7 @@ var ( StartRpc bool StartWebSockets bool RpcPort int + WsPort int NatType string PMPGateway string OutboundPort string @@ -96,6 +97,7 @@ func Init() { flag.StringVar(&PMPGateway, "pmp", "", "Gateway IP for PMP") flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers") flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") + flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on") flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server") flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index b816c678e..92dbf5a6f 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -131,7 +131,7 @@ func main() { } if StartWebSockets { - utils.StartWebSockets(ethereum) + utils.StartWebSockets(ethereum, WsPort) } utils.StartEthereum(ethereum, UseSeed) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 13fbc7c64..437e0c037 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -39,8 +39,9 @@ import ( "github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/rlp" rpchttp "github.com/ethereum/go-ethereum/rpc/http" + rpcws "github.com/ethereum/go-ethereum/rpc/websocket" "github.com/ethereum/go-ethereum/state" - "github.com/ethereum/go-ethereum/websocket" + // "github.com/ethereum/go-ethereum/websocket" "github.com/ethereum/go-ethereum/xeth" ) @@ -201,11 +202,18 @@ func StartRpc(ethereum *eth.Ethereum, RpcPort int) { } } -func StartWebSockets(eth *eth.Ethereum) { +func StartWebSockets(eth *eth.Ethereum, wsPort int) { clilogger.Infoln("Starting WebSockets") - sock := websocket.NewWebSocketServer(eth) - go sock.Serv() + // sock := websocket.NewWebSocketServer(eth) + // go sock.Serv() + var err error + eth.WsServer, err = rpcws.NewWebSocketServer(eth, wsPort) + if err != nil { + clilogger.Errorf("Could not start RPC interface (port %v): %v", wsPort, err) + } else { + go eth.WsServer.Start() + } } var gminer *miner.Miner diff --git a/eth/backend.go b/eth/backend.go index fbe080618..ab30a1b38 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -67,6 +67,7 @@ type Ethereum struct { blockSub event.Subscription RpcServer rpc.RpcServer + WsServer rpc.RpcServer keyManager *crypto.KeyManager clientIdentity p2p.ClientIdentity @@ -276,6 +277,9 @@ func (s *Ethereum) Stop() { if s.RpcServer != nil { s.RpcServer.Stop() } + if s.WsServer != nil { + s.WsServer.Stop() + } s.txPool.Stop() s.eventMux.Stop() s.blockPool.Stop()