angelcool@fedora-laptop$cat FILE1.txt
1
2
3
4
5
5
angelcool@fedora-laptop$cat FILE2.txt
1
2
3
4
5
6
7
8
9
angelcool@fedora-laptop$comm -13 <(sort FILE1.txt|uniq) <(sort FILE2.txt|uniq)
6
7
8
9
angelcool@fedora-laptop$ man comm
...
Compare sorted files FILE1 and FILE2 line by line.
When FILE1 or FILE2 (not both) is -, read standard input.
With no options, produce three-column output. Column one contains lines unique to FILE1, column two con‐
tains lines unique to FILE2, and column three contains lines common to both files.
-1 suppress column 1 (lines unique to FILE1)
-2 suppress column 2 (lines unique to FILE2)
-3 suppress column 3 (lines that appear in both files)
--check-order
check that the input is correctly sorted, even if all input lines are pairable
--nocheck-order
do not check that the input is correctly sorted
--output-delimiter=STR
separate columns with STR
--total
output a summary
-z, --zero-terminated
line delimiter is NUL, not newline
--help display this help and exit
--version
output version information and exit
Note, comparisons honor the rules specified by 'LC_COLLATE'.
...
[ view entry ] ( 78 views ) | print article
angelcool@fedora-laptop$date
Sat Nov 23 05:57:16 PM PST 2024
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$java --version
openjdk 17.0.13 2024-10-15
OpenJDK Runtime Environment (Red_Hat-17.0.13.0.11-1) (build 17.0.13+11)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.13.0.11-1) (build 17.0.13+11, mixed mode, sharing)
angelcool@fedora-laptop$jar --version
jar 17.0.13
angelcool@fedora-laptop$
angelcool@fedora-laptop$pwd
/home/angelcool/java-practice/HelloWorldServlet
angelcool@fedora-laptop$tree
.
├── deploy
│ └── helloworld.war
├── Notes.txt
├── src
│ ├── HelloWorld.class
│ └── HelloWorld.java
└── web
└── WEB-INF
├── classes
│ └── com
│ └── coolwriter
│ └── helloworld
│ └── HelloWorld.class
└── web.xml
9 directories, 6 files
angelcool@fedora-laptop$
angelcool@fedora-laptop$cat Notes.txt
# Compile java class, this will create HelloWorld.class
angelcool@fedora-laptop$javac --class-path /usr/share/tomcat/lib/tomcat-servlet-api.jar src/HelloWorld.java
# Copy compiled .class file to WEB-INF
angelcool@fedora-laptop$cp src/HelloWorld.class web/WEB-INF/classes/com/coolwriter/helloworld/
# Create WAR file
angelcool@fedora-laptop$jar cvf deploy/helloworld.war -C web .
# Move WAR file to Tomcat webapps directory
angelcool@fedora-laptop$sudo cp deploy/helloworld.war /usr/share/tomcat/webapps/
# Reload servlet in /manager page ( or restart Tomcat I think )
# Access servlet: http://localhost:8080/helloworld/Hello
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$cat web/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web- ... ">
<display-name>Hello World!</display-name>
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>com.coolwriter.helloworld.HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/Hello</url-pattern>
</servlet-mapping>
</web-app>
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$cat src/HelloWorld.java
package com.coolwriter.helloworld;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class HelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String msg = this.getGreeting();
out.println(msg);
}
private String getGreeting()
{
String msg = null;
int rand = (int) (Math.random() * (6)) +1;
switch (rand) {
case 1:
msg = "Hello There!";
break;
case 2:
msg = "Hello Friend!";
break;
case 3:
msg = "Hello Stranger!";
break;
case 4:
msg = "Hello! My name is Angel!";
break;
default:
msg = "Hello World!";
}
return msg;
}
}
angelcool@fedora-laptop$
angelcool@fedora-laptop$
[ view entry ] ( 83 views ) | print article
angelcool@fedora-laptop$date
Sat Nov 23 12:00:14 PM PST 2024
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$cat /etc/redhat-release
Fedora release 39 (Thirty Nine)
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$dnf info tomcat
Last metadata expiration check: 0:42:59 ago on Sat 23 Nov 2024 11:18:54 AM PST.
Installed Packages
Name : tomcat
Epoch : 1
Version : 9.0.96
Release : 1.fc39
Architecture : noarch
Size : 323 k
Source : tomcat-9.0.96-1.fc39.src.rpm
Repository : @System
From repo : updates
Summary : Apache Servlet/JSP Engine, RI for Servlet 4.0/JSP 2.3 API
URL : http://tomcat.apache.org/
License : ASL 2.0
Description : Tomcat is the servlet container that is used in the official Reference
: Implementation for the Java Servlet and JavaServer Pages technologies.
: The Java Servlet and JavaServer Pages specifications are developed by
: Sun under the Java Community Process.
:
: Tomcat is developed in an open and participatory environment and
: released under the Apache Software License version 2.0. Tomcat is intended
: to be a collaboration of the best-of-breed developers from around the world.
angelcool@fedora-laptop$
angelcool@fedora-laptop$sudo dnf install tomcat
...
angelcool@fedora-laptop$sudo dnf install tomcat-admin-webapps
...
angelcool@fedora-laptop$sudo dnf install tomcat-docs-webapp
...
angelcool@fedora-laptop$sudo systemctl start tomcat.service
...
Enable admin user, uncomment the following in /etc/tomcat/tomcat-users.xml
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user name="admin" password="admin" roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status" />
Restart server and go to: http://localhost:8080/manager/html
For reference:
angelcool@fedora-laptop$
angelcool@fedora-laptop$tree /usr/share/tomcat/webapps/
/usr/share/tomcat/webapps/
├── host-manager
│ ├── css
│ │ └── manager.css
│ ├── images
│ │ ├── asf-logo.svg
│ │ └── tomcat.svg
│ ├── index.jsp
│ ├── META-INF
│ │ └── context.xml
│ └── WEB-INF
│ ├── jsp
│ │ ├── 401.jsp
│ │ ├── 403.jsp
│ │ └── 404.jsp
│ ├── manager.xml
│ └── web.xml
└── manager
├── css
│ └── manager.css
├── images
│ ├── asf-logo.svg
│ └── tomcat.svg
├── index.jsp
├── META-INF
│ └── context.xml
├── status.xsd
├── WEB-INF
│ ├── jsp
│ │ ├── 401.jsp
│ │ ├── 403.jsp
│ │ ├── 404.jsp
│ │ ├── connectorCerts.jsp
│ │ ├── connectorCiphers.jsp
│ │ ├── connectorTrustedCerts.jsp
│ │ ├── sessionDetail.jsp
│ │ └── sessionsList.jsp
│ └── web.xml
└── xform.xsl
13 directories, 26 files
angelcool@fedora-laptop$
[ view entry ] ( 80 views ) | print article
Miscellaneous notes for troubleshooting, gathering information about a redis/valkey setup, etc.
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ date
Sat 06 Jul 2024 04:44:24 PM PDT
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli --version
redis-cli 5.0.7
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ ### Find out node's role
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli -c -p 7000 INFO|grep role
role:master
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ ### If node is master...
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli -c -p 7000 INFO|grep slave0
slave0:ip=127.0.0.1,port=7005,state=online,offset=7532,lag=0
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ ### Verify this node is slave...
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli -c -p 7005 INFO|grep role
role:slave
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ ### Find out node's master...
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli -c -p 7005 INFO | egrep "master_(host|port)"
master_host:127.0.0.1
master_port:7000
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ ### Find out node's mode...
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli -c -p 7003 INFO | egrep mode
redis_mode:cluster
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ ### List all cluster nodes
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli -c -p 7004 CLUSTER NODES
99f95692421cd04661c93ef9f09e058a7a80a6e4 127.0.0.1:7002@17002 master - 0 1720310325000 3 connected 10923-16383
8589237392750f2df8618bcda4e92e3996dda07a 127.0.0.1:7005@17005 slave 02c090059770ba140c14a1f26a16b3457fd58bf1 0 1720310324000 6 connected
c53fa6a32d9646c21549346716f01a5147cb8bb9 127.0.0.1:7001@17001 master - 0 1720310325468 2 connected 5461-10922
02c090059770ba140c14a1f26a16b3457fd58bf1 127.0.0.1:7000@17000 master - 0 1720310325000 1 connected 0-5460
ed206ea99f372d34dee37433b7747b5f2b2a3a40 127.0.0.1:7003@17003 slave c53fa6a32d9646c21549346716f01a5147cb8bb9 0 1720310325567 4 connected
05fe8b609e4b13d0510ed9b32b27b84502898595 127.0.0.1:7004@17004 myself,slave 99f95692421cd04661c93ef9f09e058a7a80a6e4 0 1720310323000 5 connected
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ ### This command seems to run INFO in all cluster nodes...
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli --cluster call 127.0.0.1:7000 INFO|grep role
role:master
role:master
role:slave
role:slave
role:slave
role:master
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ ### monitor node
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli -c -p 7005 monitor
...
Find out data directory and config path:
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ ####### FIND PATH for rdb AND aof FILES!!!! #######
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli -c -p 7000 CONFIG GET dir
1) "dir"
2) "/home/acool/redis-cluster/7000"
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli --cluster call 127.0.0.1:7000 CONFIG GET dir
>>> Calling CONFIG GET dir
127.0.0.1:7000: dir
/home/acool/redis-cluster/7000
127.0.0.1:7001: dir
/home/acool/redis-cluster/7001
127.0.0.1:7004: dir
/home/acool/redis-cluster/7004
127.0.0.1:7005: dir
/home/acool/redis-cluster/7005
127.0.0.1:7003: dir
/home/acool/redis-cluster/7003
127.0.0.1:7002: dir
/home/acool/redis-cluster/7002
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ redis-cli --cluster call 127.0.0.1:7000 INFO | grep -i config_file
...
[ view entry ] ( 188 views ) | print article
[acool@localhost ~]$ date
Fri Jul 5 01:48:53 PM PDT 2024
[acool@localhost ~]$ cat /etc/redhat-release
Fedora release 38 (Thirty Eight)
[acool@localhost ~]$ sudo dnf install valkey
...
[acool@localhost ~]$ valkey-cli --version
valkey-cli 7.2.4
[acool@localhost ~]$
[acool@localhost ~]$ # just in case...
[acool@localhost ~]$ systemctl stop valkey.service
[acool@localhost ~]$ systemctl status valkey.service
...
[acool@localhost ~]$ which valkey-server
/usr/bin/valkey-server
[acool@localhost ~]$
[acool@localhost ~]$ mkdir valkey-cluster-demo
[acool@localhost ~]$ cd valkey-cluster-demo/
[acool@localhost valkey-cluster-demo]$ vim valkey.conf
...
[acool@localhost valkey-cluster-demo]$ cat valkey.conf
port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
[acool@localhost valkey-cluster-demo]$
[acool@localhost valkey-cluster-demo]$ mkdir cluster-test
[acool@localhost valkey-cluster-demo]$ cd cluster-test/
[acool@localhost cluster-test]$ mkdir -p {7000..7005}
[acool@localhost cluster-test]$ for i in {7000..7005}; do cp ../valkey.conf $i; done
[acool@localhost cluster-test]$ # open 7 tabs, update ports and start servers
[acool@localhost cluster-test]$ # TIP to update ports: for i in {0..5}; do sed -i 's/7000/700'"$i"'/g' "700$i/redis.conf" ; done
[acool@localhost cluster-test]$ cd 7000/
[acool@localhost 7000]$ /usr/bin/valkey-server ./valkey.conf
...
[acool@localhost valkey-cluster-demo] # create cluster
[acool@localhost valkey-cluster-demo]$ valkey-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1
...
[acool@localhost valkey-cluster-demo]$ valkey-cli -p 7000 cluster nodes
384d585df521f8588a03b57a38e871549c0e58c4 127.0.0.1:7001@17001 master - 0 1720214911355 2 connected 5461-10922
5d2edcbba8f394a612df5253bd19a9399f97f4ff 127.0.0.1:7002@17002 master - 0 1720214912358 3 connected 10923-16383
4cf4150f20ae444422f0dabbc29b0a75878b1a2d 127.0.0.1:7004@17004 slave c88d6bea070f64023a2c7f27831bbbd113b2ff03 0 1720214912000 1 connected
e40a58e318f277ce2d420f7cb77480d5643c28c4 127.0.0.1:7005@17005 slave 384d585df521f8588a03b57a38e871549c0e58c4 0 1720214913362 2 connected
c88d6bea070f64023a2c7f27831bbbd113b2ff03 127.0.0.1:7000@17000 myself,master - 0 1720214912000 1 connected 0-5460
5b13cd8e34b47890e88fb48e30a99174ba19b751 127.0.0.1:7003@17003 slave 5d2edcbba8f394a612df5253bd19a9399f97f4ff 0 1720214911354 3 connected
[acool@localhost valkey-cluster-demo]$
[acool@localhost valkey-cluster-demo]$
[acool@localhost valkey-cluster-demo]$ # To connect to Valkey Cluster, you'll need a cluster-aware Valkey client...
[acool@localhost valkey-cluster-demo]$ # ...store some keys
[acool@localhost valkey-cluster-demo]$ valkey-cli -c -p 7000
127.0.0.1:7000> set firstname Angel
-> Redirected to slot [7108] located at 127.0.0.1:7001
OK
127.0.0.1:7001> set lastname Cool
OK
127.0.0.1:7001>exit
[acool@localhost valkey-cluster-demo]$
[acool@localhost valkey-cluster-demo]$ # Retrive some keys
[acool@localhost valkey-cluster-demo]$ valkey-cli -c -p 7005
127.0.0.1:7005> get lastname
-> Redirected to slot [7726] located at 127.0.0.1:7001
"Cool"
127.0.0.1:7001> get firstname
"Angel"
127.0.0.1:7001>exit
[acool@localhost valkey-cluster-demo]$
[acool@localhost valkey-cluster-demo]$
TIP: Easy way to start all servers:
acool@acool-HP-EliteBook-8440p:~/redis-cluster$ for i in {0..5}; do cd /home/acool/redis-cluster/700$i && /usr/bin/redis-server redis.conf --daemonize yes; done
Bonus: Pub/Sub demo
[acool@localhost valkey-cluster-demo]$ # TERMINAL 1
[acool@localhost valkey-cluster-demo]$ valkey-cli -c -p 7001
127.0.0.1:7001> SUBSCRIBE channel-a
...
[acool@localhost valkey-cluster-demo]$ # TERMINAL 2
[acool@localhost valkey-cluster-demo]$ valkey-cli -c -p 7002
127.0.0.1:7002> SUBSCRIBE channel-b
...
[acool@localhost valkey-cluster-demo]$ # TERMINAL 3
[acool@localhost valkey-cluster-demo]$ valkey-cli -c -p 7000
127.0.0.1:7000> PUBLISH channel-a "Hello channel a!"
(integer) 0
127.0.0.1:7000> PUBLISH channel-b "Hello channel b!"
(integer) 0
127.0.0.1:7000>
127.0.0.1:7000> exit
[acool@localhost valkey-cluster-demo]$ # Monitor output in TERMINAL 1 and 2
[ view entry ] ( 198 views ) | print article
angelcool@fedora-laptop$
angelcool@fedora-laptop$date
Fri Apr 12 07:51:16 PM PDT 2024
angelcool@fedora-laptop$ls lib/
coolprogram.ex coordinator.ex worker.ex
angelcool@fedora-laptop$cat lib/coolprogram.ex
defmodule CoolProgram do
def temperature_of(cities) do
coordinator_pid = spawn(CoolProgram.Coordinator, :loop, [[], Enum.count(cities)])
cities |> Enum.each(fn city ->
worker_pid = spawn(CoolProgram.Worker, :loop, [])
send(worker_pid, {coordinator_pid, city})
end)
end
end
angelcool@fedora-laptop$cat lib/coordinator.ex
defmodule CoolProgram.Coordinator do
def loop(results \\ [], results_expected) do
receive do
{:ok, result} ->
new_results = [result|results]
if results_expected == Enum.count(new_results) do
send(self(), :exit)
end
loop(new_results, results_expected)
:exit ->
IO.puts(results |> Enum.sort |> Enum.join(", "))
_->
loop(results, results_expected)
end
end
end
angelcool@fedora-laptop$cat lib/worker.ex
defmodule CoolProgram.Worker do
def temperature_of(location) do
result = url_for(location)
|> HTTPoison.get
|> parse_response
case result do
{:ok, temp} ->
"#{location}: #{temp}° C"
:error ->
"#{location} not found"
end
end
defp url_for(location) do
location = URI.encode(location)
"http://api.openweathermap.org/data/2.5/weather?q=#{location}&appid=#{apikey()}"
end
defp parse_response({:ok, %HTTPoison.Response{body: body, status_code: 200}}) do
body
|> JSON.decode!
|> compute_temperature()
end
defp parse_response(_) do
:error
end
defp compute_temperature(json) do
try do
temp = (json["main"]["temp"]-273.15)
|> Float.round(1)
{:ok, temp}
rescue
_-> :error
end
end
defp apikey do
"XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
end
def loop do
receive do
{sender_pid, location}->
send(sender_pid, {:ok, temperature_of(location)})
_->
IO.puts "don't know how to process this message"
end
loop()
end
end
angelcool@fedora-laptop$
angelcool@fedora-laptop$iex --version
IEx 1.15.7 (compiled with Erlang/OTP 26)
angelcool@fedora-laptop$iex -S mix
Compiling 1 file (.ex)
Erlang/OTP 26 [erts-14.2.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> cities=["San Diego", "Merida", "Singapore", "Los Angeles", "Mexico City", "Miami", "Temecula", "Buenos Aires", "Ojai" ]
["San Diego", "Merida", "Singapore", "Los Angeles", "Mexico City", "Miami",
"Temecula", "Buenos Aires", "Ojai"]
iex(2)> CoolProgram.temperature_of(cities)
:ok
Buenos Aires: 17.0° C, Los Angeles: 14.7° C, Merida: 25.0° C, Mexico City: 22.8° C, Miami: 22.0° C, Ojai: 14.2° C, San Diego: 15.2° C, Singapore: 30.8° C, Temecula: 13.1° C
iex(3)>
[ view entry ] ( 211 views ) | print article
# Filtering files in a directory by filename
angelcool@fedora-laptop$date
Fri Apr 12 12:02:42 PM PDT 2024
angelcool@fedora-laptop$iex
...
iex(90)> "/home/angelcool/Downloads" \
...(90)> |> Path.join("**/*.rpm") \
...(90)> |> Path.wildcard \
...(90)> |> Enum.filter(fn fname -> String.contains?(Path.basename(fname),"dbeaver") end)
["/home/angelcool/Downloads/dbeaver-ce-24.0.2-stable.x86_64.rpm"]
# Making an HTTP GET request
iex(18)> :inets.start()
:ok
iex(19)> :ssl.start()
:ok
iex(20)> :httpc.request(:get, {'https://www.angelcool.net', []}, [ssl: :httpc.ssl_verify_host_options(true)], [])
...
[ view entry ] ( 199 views ) | print article
angelcool@fedora-laptop$ # Let's get the date and versions used
angelcool@fedora-laptop$date
Sat Apr 6 11:51:08 AM PDT 2024
angelcool@fedora-laptop$iex --version
IEx 1.15.7 (compiled with Erlang/OTP 26)
angelcool@fedora-laptop$mix --version
Erlang/OTP 26 [erts-14.2.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Mix 1.15.7 (compiled with Erlang/OTP 26)
angelcool@fedora-laptop$mix phx.new --version
Phoenix installer v1.7.11
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$
angelcool@fedora-laptop$ # The gist of this post...
angelcool@fedora-laptop$
angelcool@fedora-laptop$ # Terminal 1
angelcool@fedora-laptop$ iex --name a@127.0.0.1
iex(a@127.0.0.1)1>
angelcool@fedora-laptop$ #Terminal 2
angelcool@fedora-laptop$ iex --name b@127.0.0.1
Erlang/OTP 26 [erts-14.2.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help)
iex(b@127.0.0.1)1> Node.connect :"a@127.0.0.1"
true
iex(b@127.0.0.1)2> Node.list
[:"a@127.0.0.1"]
iex(b@127.0.0.1)3>
# Terminal 1
iex(a@127.0.0.1)> Agent.start(
fn -> %{hello: "world"} end,
name: {:global, GlobalAgent}
)
{:ok, #PID<0.116.0>}
# Terminal 2
iex(b@127.0.0.1)4> Agent.get {:global,GlobalAgent}, &(&1)
%{hello: "world"}
# Terminal 2 - Update state
iex(b@127.0.0.1)5> Agent.update {:global, GlobalAgent}, fn _ -> %{hello: "everyone!"} end
:ok
iex(b@127.0.0.1)6>
# Terminal 2 - Get new state
iex(b@127.0.0.1)6> Agent.get {:global,GlobalAgent}, &(&1)
%{hello: "everyone!"}
# Terminal 1 - Get new state
iex(a@127.0.0.1)2> Agent.get {:global,GlobalAgent}, &(&1)
%{hello: "everyone!"}
[ view entry ] ( 248 views ) | print article
angelcool@fedora-laptop$date
Tue Apr 2 11:31:57 AM PDT 2024
angelcool@fedora-laptop$mix new process-demo --app process_a
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/process_a.ex
* creating test
* creating test/test_helper.exs
* creating test/process_a_test.exs
Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:
cd process-demo
mix test
Run "mix help" for more commands.
angelcool@fedora-laptop$
angelcool@fedora-laptop$cd process-demo/
angelcool@fedora-laptop$ls -l
total 8
drwxr-xr-x. 1 angelcool angelcool 24 Apr 2 11:31 lib
-rw-r--r--. 1 angelcool angelcool 575 Apr 2 11:31 mix.exs
-rw-r--r--. 1 angelcool angelcool 476 Apr 2 11:31 README.md
drwxr-xr-x. 1 angelcool angelcool 66 Apr 2 11:31 test
angelcool@fedora-laptop$
angelcool@fedora-laptop$cat lib/process_a.ex
defmodule ProcessA do
def receiverA(count) do
receive do
{from, message} -> send(from, {"Greetings from ProcessA!.", message})
receiverA(count+1)
end
end
end
angelcool@fedora-laptop$cat lib/process_b.ex
defmodule ProcessB do
def initialize do
pid_A = spawn(ProcessA, :receiverA, [1])
recieverB(pid_A)
end
def recieverB(pid_A) do
receive do
{message} ->
send(pid_A, {self(), message})
recieverB(pid_A)
{response, originalmessage} ->
IO.puts("Response: #{response}")
IO.puts("Original Message: #{originalmessage}")
recieverB(pid_A)
end
end
end
angelcool@fedora-laptop$
angelcool@fedora-laptop$iex --version
IEx 1.15.7 (compiled with Erlang/OTP 26)
angelcool@fedora-laptop$
angelcool@fedora-laptop$mix phx.new --version
Phoenix installer v1.7.11
angelcool@fedora-laptop$
angelcool@fedora-laptop$iex -S mix
Compiling 2 files (.ex)
Generated process_a app
Erlang/OTP 26 [erts-14.2.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]
Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> pid_B = spawn(ProcessB, :initialize, [])
#PID<0.166.0>
iex(2)> send(pid_B, {"Hi! This is a message from process B!"})
Response: Greetings from ProcessA!.
{"Hi! This is a message from process B!"}
Original Message: Hi! This is a message from process B!
iex(3)>
[ view entry ] ( 232 views ) | print article
HOST A - SERVER
angelcool@2603-8000-6a00-5748-xxxx-xxxx-xxxx-xxxx:~$ date
Sun Mar 3 02:04:35 PM PST 2024
#IPv4
angelcool@2603-8000-6a00-5748-xxxx-xxxx-xxxx-xxxx:~$ iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 128 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.184 port 5001 connected with 192.168.1.192 port 57642 (icwnd/mss/irtt=14/1448/515)
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.01 sec 1.10 GBytes 941 Mbits/sec
angelcool@2603-8000-6a00-5748-xxxx-xxxx-xxxx-xxxx:~$
angelcool@2603-8000-6a00-5748-xxxx-xxxx-xxxx-xxxx:~$
# IPv6
angelcool@2603-8000-6a00-5748-xxxx-xxxx-xxxx-xxxx:~$ iperf -s -V
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 128 KByte (default)
------------------------------------------------------------
[ 1] local 2603:8000:6a00:5748:xxxx:xxxx:xxxx:xxxx port 5001 connected with 2603:8000:6a00:5748:xxxx:xxxx:xxxx:xxxx port 56868 (icwnd/mss/irtt=13/1428/460)
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.02 sec 1.08 GBytes 928 Mbits/sec
angelcool@2603-8000-6a00-5748-xxxx-xxxx-xxxx-xxxx:~$
HOST B - CLIENT
acool@localhost ~]$
# IPv4
[acool@localhost ~]$ iperf -c 192.168.1.184
------------------------------------------------------------
Client connecting to 192.168.1.184, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.192 port 57642 connected with 192.168.1.184 port 5001 (icwnd/mss/irtt=14/1448/731)
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.02 sec 1.10 GBytes 940 Mbits/sec
# IPv6
[acool@localhost ~]$ iperf -c 2603:8000:6a00:xxxx:xxxx:xxxx:xxxx
------------------------------------------------------------
Client connecting to 2603:8000:6a00:xxxx:xxxx:xxxx:xxxx, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 2603:8000:6a00:5748:: port 56868 connected with 2603:8000:6a00:5748:xxxx:xxxx:xxxx:xxxx port 5001 (icwnd/mss/irtt=13/1428/783)
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.02 sec 1.08 GBytes 928 Mbits/sec
[acool@localhost ~]$
[ view entry ] ( 220 views ) | print article
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next> Last>>