Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
a88f609b
Commit
a88f609b
authored
Jan 28, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use custom Send methods
parent
e9d017ba
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
7 deletions
+11
-7
server.go
rpc/ws/server.go
+11
-7
No files found.
rpc/ws/server.go
View file @
a88f609b
...
...
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
package
ws
package
rpc
ws
import
(
"fmt"
...
...
@@ -30,6 +30,7 @@ import (
)
var
wslogger
=
logger
.
NewLogger
(
"RPC-WS"
)
var
JSON
rpc
.
JsonWrapper
type
WebSocketServer
struct
{
eth
*
eth
.
Ethereum
...
...
@@ -98,25 +99,28 @@ func (s *WebSocketServer) apiHandler(api *rpc.EthereumApi) http.Handler {
func
sockHandler
(
api
*
rpc
.
EthereumApi
)
websocket
.
Handler
{
fn
:=
func
(
conn
*
websocket
.
Conn
)
{
for
{
wslogger
.
Debugln
(
"Handling
request
"
)
wslogger
.
Debugln
(
"Handling
connection
"
)
var
reqParsed
rpc
.
RpcRequest
// reqParsed, reqerr := JSON.ParseRequestBody(conn.Request())
if
err
:=
websocket
.
JSON
.
Receive
(
conn
,
&
reqParsed
);
err
!=
nil
{
wslogger
.
Debugln
(
rpc
.
ErrorParseRequest
)
websocket
.
JSON
.
Send
(
conn
,
rpc
.
RpcErrorResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
true
,
ErrorText
:
rpc
.
ErrorParseRequest
})
// if reqerr != nil {
JSON
.
Send
(
conn
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
true
,
ErrorText
:
rpc
.
ErrorParseRequest
})
// websocket.JSON.Send(conn, rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: rpc.ErrorParseRequest})
continue
}
var
response
interface
{}
reserr
:=
api
.
GetRequestReply
(
&
reqParsed
,
&
response
)
if
reserr
!=
nil
{
wslogger
.
Errorln
(
reserr
)
websocket
.
JSON
.
Send
(
conn
,
rpc
.
RpcErrorResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
true
,
ErrorText
:
reserr
.
Error
()})
// websocket.JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: reserr.Error()}
)
JSON
.
Send
(
conn
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
true
,
ErrorText
:
reserr
.
Error
()})
continue
}
wslogger
.
Debugf
(
"Generated response: %T %s"
,
response
,
response
)
websocket
.
JSON
.
Send
(
conn
,
rpc
.
RpcSuccessResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
false
,
Result
:
response
})
JSON
.
Send
(
conn
,
&
rpc
.
RpcSuccessResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
false
,
Result
:
response
})
// websocket.JSON.Send(conn, rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response})
}
}
return
websocket
.
Handler
(
fn
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment