diff --git a/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Client Example.gaml b/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Client Example.gaml deleted file mode 100644 index 94279003d4..0000000000 --- a/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Client Example.gaml +++ /dev/null @@ -1,40 +0,0 @@ -/** -* Name: Socket_TCP_HelloWorld_Client -* Author: Arnaud Grignard -* Description: Two clients are communicated throught the Socket TCP protocol. -* Tags: Network, TCP, Socket -*/ -model Socket_TCP_HelloWorld_Client - - -global { - init { - create Networking_Client number:3 { - // replace the "localhost" address by the IP address of the other computer - do connect to: "localhost" protocol: "tcp_client" port: 3001 with_name: "Client"; - do join_group with_name:"client_group"; - } - } - -} - -species Networking_Client skills: [network] { - reflex receive when:has_more_message() { - loop while:has_more_message() { - message mm <- fetch_message(); - write mm.contents; - } - } - - reflex send when:every(4#cycle) { - do send to: "server_group" contents: name + " at " + cycle + " sent to Server a message"; - } -} - -experiment "TCP Client" type: gui -{ - output - { - } - -} diff --git a/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Server And Client Example .gaml b/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Server And Client Example .gaml new file mode 100644 index 0000000000..83c4b7d749 --- /dev/null +++ b/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Server And Client Example .gaml @@ -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 { + } + +} diff --git a/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Server Example .gaml b/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Server Example .gaml deleted file mode 100644 index 14f5656306..0000000000 --- a/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Server Example .gaml +++ /dev/null @@ -1,62 +0,0 @@ -/** -* 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; - init - { - - create Networking_server number:4 - { - do connect protocol: "tcp_server" port: 3001 with_name: "Server"+id; - do join_group with_name:"server_group"; - id<-id+1; - color <- rnd_color(255); - } - - ask one_of(Networking_server) { - isLeader <- true; - } - - } - -} - -species Networking_server skills: [network] -{ - 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: every(3#cycle) and isLeader - { - do send to: "server_group" contents: ("I am Server Leader " + name + " I give order to other Servers"); - do send to: "client_group" contents: ("I am Server " + name + " I give order to Clients"); - } - -} - -experiment "TCP Server Test" type: gui -{ - output - { - } - -} diff --git a/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Teleportation.gaml b/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Teleportation.gaml index 8c49a1578b..3fba84fc91 100644 --- a/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Teleportation.gaml +++ b/ummisco.gama.network/models/Network/2 Available protocols/TCP protocol/TCP Teleportation.gaml @@ -6,136 +6,129 @@ * buffer zone, it is teleported to the next simulation (remove from the first and created inside the next one). * Tags: Network, TCP, multi-simulation */ - - model PongTeleportation global { int numberOfSimulation <- 3; int simulation_id <- 0; string prefixName <- "SIMULATION_"; - geometry shape <- rectangle(200,100); - - - init - { - name <- prefixName+simulation_id; - - create Pong number:10{ + geometry shape <- rectangle(200, 100); + + init { + name <- prefixName + simulation_id; + create Pong number: 10 { myColor <- rnd_color(255); } - create Buffer with:[zone::0]; - create Buffer with:[zone::1]; + + create Buffer with: [zone::0]; + create Buffer with: [zone::1]; } -} +} -species Buffer skills:[network] -{ +species Buffer skills: [network] { int zone; string next_agent; - init{ - name <- "buffer_"+world.name+string(zone); - next_agent <- "buffer_"+(world.prefixName+((1+simulation_id) mod numberOfSimulation)) +string((zone+1)mod 2); - shape <- rectangle(10,100); - if(zone = 0){ - location <- point(5,50); + + init { + name <- "buffer_" + world.name + string(zone); + next_agent <- "buffer_" + (world.prefixName + ((1 + simulation_id) mod numberOfSimulation)) + string((zone + 1) mod 2); + shape <- rectangle(10, 100); + if (zone = 0) { + location <- point(5, 50); } else { - location <- point(195,50); - } - - if(simulation_id = 0) - { - do connect to:"localhost" with_name:name protocol:"tcp_server" port:3001; - + location <- point(195, 50); } - else - { - do connect to:"localhost" with_name:name protocol:"tcp_client" port:3001; - + + if (simulation_id = 0) { + do connect to: "localhost" with_name: name protocol: "tcp_server" port: 3001; + do join_group with_name: "server_group"; + } else { + do connect to: "localhost" with_name: name protocol: "tcp_client" port: 3001; + do join_group with_name: "buffer"; + write "my name " + name + " " + next_agent; } - - do connect with_name:name; - do join_group with_name:"buffer"; - write "my name "+ name +" " + next_agent; + } - - reflex teleport{ - list to_move <- Pong where(each.last_zone = -1 and each overlaps shape); - loop ping over:to_move - { + + reflex teleport { + list to_move <- Pong where (each.last_zone = -1 and each overlaps shape); + loop ping over: to_move { write "send agent"; - map msg <- map(["name"::ping.name,"mcolor"::ping.myColor, "location"::(ping.location - {self.location.x,0})]); + map msg <- map(["name"::ping.name, "mcolor"::ping.myColor, "location"::(ping.location - {self.location.x, 0})]); string smsg <- serialize(msg); - do send to:next_agent contents:msg; - ask ping { do die;} + do send to: next_agent contents: msg; + ask ping { + do die; + } + } + } - reflex enable_teleport{ - list internal <- Pong where(each.last_zone = self.zone and !( self.shape overlaps each.location)); - + + reflex enable_teleport { + list internal <- Pong where (each.last_zone = self.zone and !(self.shape overlaps each.location)); ask internal { last_zone <- -1; } + } - - - + reflex retrieve_agent when: has_more_message() { - loop while:has_more_message() - { + loop while: has_more_message() { message msg <- fetch_message(); map details <- map(msg.contents); - create Pong with:[name::details["name"],myColor::details["mcolor"],location::details["location"]] - { - location <- {myself.location.x,location.y}; + create Pong with: [name:: details["name"], myColor::details["mcolor"], location::details["location"]] { + write "received agent"; + location <- {myself.location.x, location.y}; last_zone <- myself.zone; } + } + } - - aspect default{ - draw shape color:#pink; + + aspect default { + draw shape color: #pink; } + } -species Pong -{ +species Pong { rgb myColor; int last_zone <- -1; - - reflex pongMove - { - location <- location + {1,0}; + + reflex pongMove { + location <- location + {1, 0}; } - - aspect default - { - draw circle(2) color:myColor; + + aspect default { + draw circle(2) color: myColor; } + } +experiment start { +//definition of a minimal duration for each cycle. As the model is very simple, it can run too fast to observe the results, so we slow it down. + float minimum_cycle_duration <- 0.05; -experiment start -{ - //definition of a minimal duration for each cycle. As the model is very simple, it can run too fast to observe the results, so we slow it down. - float minimum_cycle_duration <- 0.1; - - init - { + init { int nb_simul <- 3; simulation_id <- 0; seed <- 1.0; - loop i from:1 to: nb_simul -1 - { - create simulation with: [simulation_id::i, seed::1+i, numberOfSimulation::nb_simul]; - + loop i from: 1 to: nb_simul - 1 { + create simulation with: [simulation_id::i, seed::1 + i, numberOfSimulation::nb_simul]; } + } - output{ - display map{ + + output { + layout horizontal([0::5000, 1::5000, 2::5000]) tabs: true editors: false; + display map { species Pong; - species Buffer transparency:0.5; + species Buffer transparency: 0.5; } + } + } \ No newline at end of file