@@ -63,11 +63,10 @@ draw_circle(x, y, 8, false);
63632. Define the following handler in the GameClient constructor:
6464```gml
6565function GameClient(_ip, _port) : TCPSocket(_ip, _port) constructor {
66- // [...]
66+ // Client received notification to create ball
6767 rpc.registerHandler("create_ball", function(_pos) {
68- // Client received notification to create ball, then let's create the ball instance
68+ // Create the ball instance
6969 instance_create_depth(_pos.x, _pos.y, 0, obj_ball);
70- // This handler doesn't have a return value, because it's a notification
7170 });
7271 static step = function() {
7372 if (mouse_check_button_pressed(mb_left)) {
@@ -83,14 +82,10 @@ function GameClient(_ip, _port) : TCPSocket(_ip, _port) constructor {
83823 . Define the following handler in the GameServer constructor:
8483``` gml
8584function GameServer (_ port) : TCPServer(_ port) constructor {
86- // [ ... ]
85+ // Server received notification to create ball
8786 rpc.registerHandler("create_ball", function(_ pos, _ socket) {
88- // Server received notification to create ball, then store the ball position
89- ballPosition = _ pos;
9087 // Send "create_ball" notification to all clients
91- clients.forEach(function(_ client_socket, _ client) {
92- rpc.sendNotification("create_ball", ballPosition, _ client_socket);
93- });
88+ rpc.sendNotification("create_ball", _ pos, sockets);
9489 });
9590}
9691```
@@ -107,12 +102,8 @@ function GameServer(_port) : TCPServer(_port) constructor {
107102 var _socket = _message.socket;
108103 // If the message type is "create_ball"
109104 if (_data.type == "create_ball") {
110- // Store the data
111- data = _data;
112105 // Send this data to all clients
113- clients.forEach(function(_client_socket) {
114- network.sendData(data, _client_socket);
115- });
106+ network.sendData(_data, sockets);
116107 }
117108 });
118109}
0 commit comments