Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7a68397

Browse files
committedFeb 6, 2020
java-labs initial commit
0 parents  commit 7a68397

File tree

8 files changed

+344
-0
lines changed

8 files changed

+344
-0
lines changed
 

‎.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Target directories.
2+
target/
3+
4+
# Eclipse configuration.
5+
.classpath
6+
.project
7+
.settings/
8+
9+
# IntelliJ IDEA configuration.
10+
.idea/
11+
12+
13+
# Netbeans configuration.
14+
/nbproject/private/
15+
/dist/
16+
/build/

‎README.md

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# java-labs: Creating the environment for Java development and Git - 2019-2020
2+
3+
## Netcat (nc)
4+
- Windows OS
5+
- Download MobaXterm from [here] (https://download.mobatek.net/1242019111120613/MobaXterm_Portable_v12.4.zip) and extract the content. No installation is needed. Netcat is available if you click on "Start local terminal".
6+
7+
- Linux OS
8+
- Netcat should already be installed on your system.
9+
10+
## NetBeans IDE 8.2 for Java SE
11+
12+
- Download NetBeans from [here](https://netbeans.org/downloads/8.2/) and install it using default options.
13+
14+
15+
## Git
16+
17+
- Download Git from [here](https://git-scm.com/downloads) and install it using default options
18+
19+
> Note that for instance in Ubuntu systems you could download and install it by simply executing the following:
20+
21+
```shell
22+
sudo apt-get install git
23+
```
24+
25+
- Basic configuration
26+
- In Windows OS, the following commands should be executed inside git-bash (`$GIT_HOME/git-bash.exe`):
27+
28+
```shell
29+
git config --global user.email "<user-login>@udc.es"
30+
git config --global user.name "<user-name>"
31+
```
32+
33+
> The following line illustrates how to set Sublime as the Git default editor, but you can use any other editor installed in your OS (you can download Sublime Text editor from [here](https://www.sublimetext.com/3))
34+
35+
```shell
36+
>Windows OS
37+
git config --global core.editor "'C:\Program Files\Sublime Text 3\sublime_text.exe' -w"
38+
39+
>Linux OS
40+
git config --global core.editor "subl -w"
41+
```
42+
43+
- [Optional] Autocompletion utility for Git in Linux OS systems:
44+
- Follow instructions from [https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion](https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion)
45+
46+
### Creation and configuration of SSH Keys
47+
48+
- From the git-bash interpreter in Windows OS systems
49+
> Generate SSH keys in the default path ($HOME/.ssh) and with default names
50+
51+
```shell
52+
ssh-keygen -t rsa -b 4096 -C "<user-login>@udc.es"
53+
```
54+
55+
- Open the browser and navigate to [https://git.fic.udc.es/profile/keys](https://git.fic.udc.es/profile/keys)
56+
- In the "Key" field, copy the public key, i.e, content of file `$HOME/.ssh/id_rsa.pub`
57+
- In the "Title" field, specify a name for the key
58+
- Click on the "Add key" button
59+
60+
- Try SSH connectivity against the Git server and add it to the list of known hosts
61+
> Answer "yes" to the question "Are you sure you want to continue connecting (yes/no)?"
62+
63+
```shell
64+
ssh -T git@git.fic.udc.es
65+
```
66+
67+
## Creating your project
68+
69+
### Create Git repository in FIC GitLab web site
70+
71+
- Open the browser and navigate to https://git.fic.udc.es/users/&lt;user-login&gt;/projects, where &lt;user-login&gt; is your user login.
72+
73+
- Click on "+" (on the right of the search box, on the top of the we page)
74+
- Click on "New project".
75+
- Specify "java-labs" as the name of the project.
76+
- Type of project must remain to "Private" (default value).
77+
78+
- <code><b>Click on the "Members" link.</b></code>
79+
- Click on the "Add member" tab, and select "telematica.redes" as the member to invite.
80+
- Choose "Master" as the role permission.
81+
- Do not fill the expiration date field.
82+
- Click on "Add to project" button.
83+
84+
85+
### Initializing your Git repository
86+
87+
- Download project template from [moodle](https://moodle.udc.es/course/view.php?id=55380) (`java-labs.zip` file)
88+
89+
```shell
90+
unzip java-labs.zip
91+
cd java-labs
92+
git init
93+
git remote add origin git@git.fic.udc.es:<user-login>/java-labs.git
94+
git add .
95+
git commit -m "java-labs initial commit"
96+
git push -u origin master
97+
```
98+
99+
NOTE that &lt;user-login&gt; must be changed by your user login.
100+
101+
### Load the project in NetBeans
102+
103+
- Click on "File" > "New Project" menu option.
104+
- Choose "Java Category" and "Java Project with Existent Sources" project type.
105+
- Click on "Next" button.
106+
- Set "java-labs" as "Project Name".
107+
- Choose folder "java-labs" as "Project Folder".
108+
- Click on "Next" button.
109+
- Click on "Add Folder ..." to add the "src" folder to the "Source Package Folders" of the project.
110+
- Click on "Finish" button.
111+
112+
### [Optional] Install a graphical client for Git
113+
114+
- Recommended option could be "GitKraken". You can download it from [here](https://www.gitkraken.com/download)
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package es.udc.redes.tutorial.copy;
2+
3+
public class Copy {
4+
5+
public static void main(String[] args) {
6+
7+
}
8+
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package es.udc.redes.tutorial.tcp.client;
2+
3+
import java.net.*;
4+
import java.io.*;
5+
6+
/**
7+
* Implements an echo client using TCP
8+
*/
9+
public class TcpClient {
10+
11+
public static void main(String argv[]) {
12+
if (argv.length != 3) {
13+
System.err.println("Format: es.udc.redes.tutorial.tcp.client.TcpClient <server_address> <port_number> <message>");
14+
System.exit(-1);
15+
}
16+
Socket socket = null;
17+
try {
18+
// Obtains the server IP address
19+
InetAddress serverAddress = InetAddress.getByName(argv[0]);
20+
// Obtains the server port
21+
int serverPort = Integer.parseInt(argv[1]);
22+
// Obtains the message
23+
String message = argv[2];
24+
// Creates the socket and establishes connection with the server
25+
socket = new Socket(serverAddress, serverPort);
26+
// Set a max. Timeout of 300 secs
27+
socket.setSoTimeout(300000);
28+
System.out.println("CLIENT: Connection established with "
29+
+ serverAddress.toString() + " port " + serverPort);
30+
// Set the input channel
31+
BufferedReader sInput = new BufferedReader(new InputStreamReader(
32+
socket.getInputStream()));
33+
// Set the output channel
34+
PrintWriter sOutput = new PrintWriter(socket.getOutputStream(), true);
35+
System.out.println("CLIENT: Sending " + message);
36+
// Send message to the server
37+
sOutput.println(message);
38+
// Receive server response
39+
String recibido = sInput.readLine();
40+
System.out.println("CLIENT: Received " + recibido);
41+
// Close streams and release connection
42+
sOutput.close();
43+
sInput.close();
44+
} catch (SocketTimeoutException e) {
45+
System.err.println("Nothing received in 300 secs");
46+
} catch (Exception e) {
47+
System.err.println("Error: " + e.getMessage());
48+
} finally {
49+
try {
50+
socket.close();
51+
} catch (IOException e) {
52+
e.printStackTrace();
53+
}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package es.udc.redes.tutorial.tcp.server;
2+
3+
import java.net.*;
4+
import java.io.*;
5+
6+
/**
7+
* Monothread TCP echo server.
8+
*/
9+
public class TcpServer {
10+
11+
public static void main(String argv[]) {
12+
if (argv.length != 1) {
13+
System.err.println("Format: es.udc.redes.tutorial.tcp.server.TcpServer <port>");
14+
System.exit(-1);
15+
}
16+
try {
17+
// Create a server socket
18+
19+
// Set a timeout of 300 secs
20+
21+
while (true) {
22+
// Wait for connections
23+
24+
// Set the input channel
25+
26+
// Set the output channel
27+
28+
// Receive the client message
29+
30+
// Send response to the client
31+
32+
// Close the streams
33+
}
34+
// Uncomment next catch clause after implementing the logic
35+
//} catch (SocketTimeoutException e) {
36+
// System.err.println("Nothing received in 300 secs ");
37+
} catch (Exception e) {
38+
System.err.println("Error: " + e.getMessage());
39+
e.printStackTrace();
40+
} finally {
41+
//Close the socket
42+
}
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package es.udc.redes.tutorial.udp.client;
2+
3+
import java.net.*;
4+
5+
/**
6+
* This example implements a Echo client using UDP
7+
*/
8+
public class UdpClient {
9+
10+
public static void main(String argv[]) {
11+
if (argv.length != 3) {
12+
System.err.println("Format: es.udc.redes.tutorial.udp.client.UdpClient <server_address> <port_number> <message>");
13+
System.exit(-1);
14+
}
15+
DatagramSocket sDatagram = null;
16+
try {
17+
18+
// Create a non connection-oriented socket
19+
// (use any available port)
20+
sDatagram = new DatagramSocket();
21+
// Set timeout to 300 secs
22+
sDatagram.setSoTimeout(300000);
23+
// Obtain server IP address from first argument
24+
InetAddress serverAddress = InetAddress.getByName(argv[0]);
25+
// Obtain server port from second argument
26+
int serverPort = Integer.parseInt(argv[1]);
27+
// Obtain message from third argument
28+
String message = argv[2];
29+
// Prepare the datagram
30+
DatagramPacket dgramSent = new DatagramPacket(message.getBytes(),
31+
message.getBytes().length, serverAddress, serverPort);
32+
// Send the datagram
33+
sDatagram.send(dgramSent);
34+
System.out.println("CLIENT: Sending "
35+
+ new String(dgramSent.getData()) + " to "
36+
+ dgramSent.getAddress().toString() + ":"
37+
+ dgramSent.getPort());
38+
// Prepare datagram for data reception
39+
byte array[] = new byte[1024];
40+
DatagramPacket dgramRec = new DatagramPacket(array, array.length);
41+
// Receive the message
42+
sDatagram.receive(dgramRec);
43+
System.out.println("CLIENT: Received "
44+
+ new String(dgramRec.getData(), 0, dgramRec.getLength())
45+
+ " from " + dgramRec.getAddress().toString() + ":"
46+
+ dgramRec.getPort());
47+
} catch (SocketTimeoutException e) {
48+
System.err.println("Nothing received in 300 secs");
49+
} catch (Exception e) {
50+
System.err.println("Error: " + e.getMessage());
51+
} finally {
52+
// Close socket to release connection
53+
sDatagram.close();
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package es.udc.redes.tutorial.udp.server;
2+
3+
import java.net.*;
4+
5+
/**
6+
* Implements an UDP Echo Server.
7+
*/
8+
public class UdpServer {
9+
10+
public static void main(String argv[]) {
11+
if (argv.length != 1) {
12+
System.err.println("Format: es.udc.redes.tutorial.udp.server.UdpServer <port_number>");
13+
System.exit(-1);
14+
}
15+
try {
16+
// Create a server socket
17+
18+
// Set max. timeout to 300 secs
19+
while (true) {
20+
// Prepare datagram for reception
21+
22+
// Receive the message
23+
24+
// Prepare datagram to send response
25+
26+
// Send response
27+
28+
}
29+
30+
// Uncomment next catch clause after implementing the logic
31+
//} catch (SocketTimeoutException e) {
32+
// System.err.println("No requests received in 300 secs ");
33+
} catch (Exception e) {
34+
System.err.println("Error: " + e.getMessage());
35+
e.printStackTrace();
36+
} finally {
37+
// Close the socket
38+
}
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package es.udc.redes.webserver;
2+
3+
public class WebServer {
4+
5+
public static void main(String[] args) {
6+
7+
}
8+
9+
}

0 commit comments

Comments
 (0)
This repository has been archived.