Skip to content

Commit 1af5532

Browse files
committed
Init
0 parents  commit 1af5532

26 files changed

+3522
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
input
2+
output
3+
terminal-chat
4+
*.exe

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch",
6+
"type": "go",
7+
"request": "launch",
8+
"mode": "auto",
9+
"program": "main.go",
10+
"args": [
11+
"-in",
12+
"input"
13+
]
14+
}
15+
]
16+
}

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Terminal Chat
2+
3+
## Content
4+
5+
- [Content](#content)
6+
- [Overview](#overview)
7+
- [Download](#download)
8+
- [Commands](#commands)
9+
- [Protocol](#protocol)
10+
- [Room URL](#room-url)
11+
- [Platforms](#platforms)
12+
- [Examples](#examples)
13+
14+
## Overview
15+
16+
It is a multiroom terminal chat. It allows communicating with UTF-8 text between different computers.
17+
18+
User can have multiple rooms at a same time. Room consists of another users. There can be only one active room at a time. When you type a message, all users from active room will receive it. You will see arrived messages from all rooms, not only from active room.
19+
20+
Room organization is independent. It is means that room organization (room name, receivers in that room, messages in that room that are visible to you) will not match on receiver side. Every receiver will have its own room organization.
21+
22+
Sender will be not able to contact receiver until receiver allows accepting of messages from this sender. Every chat side (sender or receiver) may stop receiving of messages from another side without any notifications.
23+
24+
## Download
25+
26+
You can download executable files in "Releases" tab.
27+
28+
## Commands
29+
30+
All interaction with the program is performed using specific commands with possible positional arguments. Every command starts with `/` sign. Everything else, including not known commands, will be treated as UTF-8 messages and will be sended to all receivers in active room. To see available commands, run the program and type `/help`.
31+
32+
## Protocol
33+
34+
Custom protocol named STTP is used for this application. See [protocol documentation](STTP.md) for more.
35+
36+
## Room URL
37+
38+
To start communication between two computers, every computer should know IP of recipient computer. At room start, the program will print possible URLs by which this room can be reached by another computer. However, it works mostly in LAN. For WAN you may need to obtain public IP by your own.
39+
40+
## Platforms
41+
42+
Supported and tested platforms are:
43+
- Linux AMD64
44+
- Windows AMD64
45+
46+
For other platforms you will need to build the program and test it by your own.
47+
48+
## Examples
49+
50+
Here is example of communication between two computers in the same LAN.
51+
52+
**Computer № 1:**
53+
54+
```
55+
Welcome to multiroom chat.
56+
Type "/help" for more information.
57+
58+
Users can reach this room using following URLs.
59+
Pick "outbound" one if available.
60+
URLs:
61+
sttp://192.168.1.235:4444/0 (outbound)
62+
sttp://172.17.0.1:4444/0 (local)
63+
64+
[main]: /user comp_2 sttp://192.168.1.249:4444/1
65+
[main]: hello!
66+
< 12:11 main: hello!
67+
> 12:11 main comp_2: hi!
68+
```
69+
70+
**Computer № 2:**
71+
72+
```
73+
Welcome to multiroom chat.
74+
Type "/help" for more information.
75+
76+
Users can reach this room using following URLs.
77+
Pick "outbound" one if available.
78+
URLs:
79+
sttp://192.168.1.249:4444/0 (outbound)
80+
sttp://172.17.0.1:3333/0 (local)
81+
82+
[main]: /room chat
83+
Users can reach this room using following URLs.
84+
Pick "outbound" one if available.
85+
URLs:
86+
sttp://192.168.1.249:4444/1 (outbound)
87+
sttp://172.17.0.1:3333/1 (local)
88+
89+
[chat]: /user comp_1 sttp://192.168.1.235:4444/0
90+
> 12:11 chat comp_1: hello!
91+
[chat]: hi!
92+
< 12:11 chat: hi!
93+
```

STTP.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Simple Text Transfer Protocol (STTP)
2+
3+
## Content
4+
- [Content](#content)
5+
- [What is it?](#what-is-it)
6+
- [Overview](#overview)
7+
- [Structure](#structure)
8+
- [URL](#url)
9+
10+
## What is it?
11+
12+
It is an application protocol created for learning purposes only. Don't intended to be real-world protocol. So, take it easy.
13+
14+
## Overview
15+
16+
The Simple Text Transfer Protocol (STTP) is an application layer protocol for transmitting text data.
17+
18+
STTP can be used both as request-response protocol or as one-way protocol. It is not intended nor for P2P architecture nor for client-server model. It is intended for direct connections between two clients, primarily in local area network.
19+
20+
STTP requires an underlying and reliable transport layer protocol. TCP, for example.
21+
22+
STTP allows processing of transmitted data by different handlers at application level. Every handler may have different logic to handle transmitted data. For routing concept of ports is used.
23+
24+
## Structure
25+
26+
It is a structure of bytes that are comes from transport protocol.
27+
28+
<table>
29+
<tr align="center">
30+
<td>offsets</td>
31+
<td>octet</td>
32+
<td colspan="8">0</td>
33+
<td colspan="8">1</td>
34+
</tr>
35+
36+
<tr align="center">
37+
<td>octet</td>
38+
<td>bit</td>
39+
<td>7</td>
40+
<td>6</td>
41+
<td>5</td>
42+
<td>4</td>
43+
<td>3</td>
44+
<td>2</td>
45+
<td>1</td>
46+
<td>0</td>
47+
<td>7</td>
48+
<td>6</td>
49+
<td>5</td>
50+
<td>4</td>
51+
<td>3</td>
52+
<td>2</td>
53+
<td>1</td>
54+
<td>0</td>
55+
</tr>
56+
57+
<tr align="center">
58+
<td>0</td>
59+
<td>0</td>
60+
<td colspan="16">payload length</td>
61+
</tr>
62+
63+
<tr align="center">
64+
<td>2</td>
65+
<td>16</td>
66+
<td colspan="8">header length</td>
67+
<td colspan="4">source port</td>
68+
<td colspan="4">destination port</td>
69+
</tr>
70+
</table>
71+
72+
This table describes header. Payload starts right after header.
73+
74+
**Payload Length (16 bits)**
75+
76+
Count of bytes that are related to actual payload.
77+
78+
**Header Length (8 bits)**
79+
80+
Count of bytes that are related to header. To offset to actual payload, you should use this value, not hard-coded fixed number based from table above.
81+
82+
**Source port (4 bits)**
83+
84+
Sender can specify for receiver where potential response is expected. Note that receiver still can use any value.
85+
86+
**Destination port (4 bits)**
87+
88+
Sender can specify for receiver, at receiver side handler at which location should handle sent data. Note that receiver still can use any handler.
89+
90+
## URL
91+
92+
STTP resources is a handlers. Handlers are identified and located on the network by URLs, using the URI scheme `sttp`.
93+
94+
Structure of STTP URL is `sttp://<IP>:<TCP PORT>/<HANDLER ID>`. Example: `sttp://192.168.1.235:4444/0`.

0 commit comments

Comments
 (0)