Sending Messages to the Server
The final bit of code found in this source file is a simple method for sending messages to
the server:
this.send = function(inMessage: string) {
console.log(`WS sending: ${inMessage}`);
connection.send(inMessage);
};
That’s really all there is to it! The caller is presumed to have constructed a valid
message, and the send() method exposed on the WebSocket instance is all it takes to
send it. It couldn’t be easier!
At this point, createSocketComm() in socketComm.ts is done, save for one key thing:
return this;
That’s the final line in this function. That allows the caller to save a reference to the
object, which is needed to be able to call the send() method later.
Do'stlaringiz bilan baham: |