Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix example model of network TCP protocool: 1. server and client in 1…
… single model 2. fix real teleport base on TCP (instead of MQTT public server)
- Loading branch information
Showing
4 changed files
with
178 additions
and
184 deletions.
There are no files selected for viewing
40 changes: 0 additions & 40 deletions
40
...co.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Client Example.gaml
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
...ork/models/Network/2 Available protocols/TCP protocol/TCP Server And Client Example .gaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* Name: Socket_TCP_HelloWorld_Server | ||
* Author: Arnaud Grignard | ||
* Description: Two clients are communicated throught the Socket TCP protocol. | ||
* Tags: Network, TCP, Socket | ||
*/ | ||
model Socket_TCP_HelloWorld_Server | ||
|
||
global{ | ||
int id <- 0; | ||
string type <- "server"; | ||
|
||
init { | ||
if (type = "server") { | ||
do create_server; | ||
} | ||
|
||
if (type = "client") { | ||
do create_client; | ||
} | ||
|
||
} | ||
|
||
action create_server { | ||
create Server number: 2 { | ||
do connect protocol: "tcp_server" port: 3001 with_name:name; | ||
do join_group with_name: "server_group"; | ||
id <- id + 1; | ||
color <- rnd_color(255); | ||
} | ||
|
||
ask one_of(Server) { | ||
isLeader <- true; | ||
} | ||
|
||
} | ||
|
||
action create_client { | ||
create Client number: 2 { | ||
// replace the "localhost" address by the IP address of the other computer | ||
do connect to: "localhost" protocol: "tcp_client" port: 3001 with_name: name; | ||
do join_group with_name: "client_group"; | ||
id <- id + 1; | ||
color <- rgb(rnd(255)); | ||
} | ||
|
||
} | ||
reflex space{ | ||
write ""; | ||
write ""; | ||
write ""; | ||
write ""; | ||
} | ||
} | ||
|
||
species Server skills: [network] parallel:true{ | ||
string dest; | ||
rgb color; | ||
bool isLeader <- false; | ||
|
||
reflex receive when: has_more_message() { | ||
loop while: has_more_message() { | ||
message mm <- fetch_message(); | ||
write name + " received : " + mm.contents color: color; | ||
} | ||
|
||
} | ||
|
||
reflex send when: isLeader { | ||
do send to: "client_group" contents: ("I am Server Leader " + name + ", I give order to client_group at " + cycle); | ||
do send to: "server_group" contents: ("I am Server Leader " + name + ", I give order to server_group"); | ||
} | ||
|
||
} | ||
|
||
species Client skills: [network] parallel:true{ | ||
rgb color; | ||
|
||
reflex receive when: has_more_message() { | ||
loop while: has_more_message() { | ||
message mm <- fetch_message(); | ||
write name + " received : " + mm.contents color: color; | ||
} | ||
|
||
} | ||
|
||
reflex send { | ||
do send to: "server_group" contents: name + " at " + cycle + " sent to server_group a message"; | ||
} | ||
|
||
} | ||
|
||
experiment "TCP Server Test" type: gui { | ||
float minimum_cycle_duration <- 0.25; | ||
|
||
init { | ||
create simulation with: [type:: "client"]; | ||
} | ||
|
||
output { | ||
} | ||
|
||
} |
62 changes: 0 additions & 62 deletions
62
...o.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Server Example .gaml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.