Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/JRPC-Client/JRPCClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,21 @@ JRPCClient >> sendNotification: aJRPCNotificationObject [

{ #category : #'private - sending' }
JRPCClient >> sendRequest: aJRPCRequestObject [
"To be implemented by concrete subclasses.
Sends aJRPCRequestObject to the server to which the client is connected.
"Sends aJRPCRequestObject to the server to which the client is connected.
Returns a JRPCSuccessResponseObject if everything goes well.
Returns a JRPCErrorResponse if something went wrong.
"

| rawResult |
rawResult := self sendRequestContent: ( self convertJRPCJsonableObjectToJSON: aJRPCRequestObject asJRPCJSON ).
^ self parseSupposedJRPCMessageObjectFromString: rawResult
]

{ #category : #'private - sending' }
JRPCClient >> sendRequestContent: aString [
"To be implemented by concrete subclasses.
Sends aString (containing an encoded JRPC object) to the server to which the client is connected.
Returns the String returned by the server.
"
^ self subclassResponsibility
]
6 changes: 3 additions & 3 deletions src/JRPC-Client/JRPCHTTPClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ JRPCHTTPClient >> initialize [
]

{ #category : #'private - sending' }
JRPCHTTPClient >> sendRequest: aJRPCRequestObject [
JRPCHTTPClient >> sendRequestContent: aString [

| result |

result := httpClient
contents: ( self convertJRPCJsonableObjectToJSON: aJRPCRequestObject asJRPCJSON );
contents: aString;
post.

^ self parseSupposedJRPCMessageObjectFromString: ( result ifNil: [ '' ] ifNotNil: #contents )
^ result ifNil: [ '' ] ifNotNil: #contents
]

{ #category : #accessing }
Expand Down
6 changes: 3 additions & 3 deletions src/JRPC-Client/JRPCStreamClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ JRPCStreamClient >> requestsSeparator: anObject [
]

{ #category : #'private - sending' }
JRPCStreamClient >> sendRequest: aJRPCRequestObject [
self convertJRPCJsonableObjectToJSON: aJRPCRequestObject asJRPCJSON on: self writeStream.
JRPCStreamClient >> sendRequestContent: aString [
self convertJRPCJsonableObjectToJSON: aString on: self writeStream.
self writeStream
nextPutAll: self requestsSeparator.

self actionAfterStreamWritten cull: self writeStream.

"Needs to parse from a String here because it is possible that the stream
provided can not do look ahead (the JSON parser needs that)."
^ self parseSupposedJRPCMessageObjectFromString: self readStream upToEnd
^ self readStream upToEnd
]

{ #category : #accessing }
Expand Down
7 changes: 3 additions & 4 deletions src/JRPC-Client/JRPCTCPClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ JRPCTCPClient >> port: anObject [
]

{ #category : #'private - sending' }
JRPCTCPClient >> sendRequest: aJRPCRequestObject [
JRPCTCPClient >> sendRequestContent: aString [
| socket result |
socket := Socket newTCP.
socket
connectTo: self address
port: self port.
socket
sendData: (self convertJRPCJsonableObjectToJSON: aJRPCRequestObject asJRPCJSON).
socket sendData: aString.
result := socket receiveData.
socket closeAndDestroy.
^ self parseSupposedJRPCMessageObjectFromString: result
^ result
]