examples

package
v0.35.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2022 License: BSD-3-Clause Imports: 0 Imported by: 0

README

<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<meta name="theme-color" content="#375EAB" />

		<title></title>
	</head>
	<body>
		<div class="topbar">
			<div class="container">
				<div class="top-heading">
					<a href="/">github.com/shuLhan/share</a>
				</div>
				<div class="menu">
					<a href="https://godoc.org/github.com/shuLhan/share">GoDoc</a>
				</div>
				<div class="menu">
					<a href="/CHANGELOG.html">Changelog</a>
				</div>
			</div>
		</div>

		<div class="page">
			<div class="container">
				<h1></h1>
				<div class="sect1">
<h2 id="_websocket_examples">WebSocket examples</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This package contains an example of chat server and client written using
WebSocket.</p>
</div>
<div class="paragraph">
<p>To run the WebSocket server, go to directory &#34;cmd/server&#34; and execute,</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ go run .</pre>
</div>
</div>
<div class="paragraph">
<p>There are three known user in the server: &#34;Groot&#34;, &#34;Thanos&#34;, and &#34;Hulk&#34;; all
of them are represented by ID 1, 2, and 3; in order.</p>
</div>
<div class="paragraph">
<p>The client example is in directory &#34;cmd/client&#34;, go to that directory and
connect to the server as user &#34;Groot&#34; by executing</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ go run . 1</pre>
</div>
</div>
<div class="paragraph">
<p>or as user &#34;Thanos&#34;,</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ go run . 2</pre>
</div>
</div>
<div class="paragraph">
<p>or as user &#34;Hulk&#34;,</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ go run . 2</pre>
</div>
</div>
<div class="paragraph">
<p>Run the server and then two or three clients, and start chatting with each
others.</p>
</div>
</div>
</div>
			</div>
			
		</div>
		

		<div class="footer">
			Copyright 2019, Shulhan &lt;ms@kilabit.info&gt;. All rights reserved.
			<br />
			Use of this source code is governed by a BSD-style license that can be
			found in the <a href="/LICENSE">LICENSE</a> file.
		</div>
	</body>
</html>

Documentation

Index

Constants

View Source
const (
	BroadcastMessage = "message"
	BroadcastSystem  = "system"
)

Variables

View Source
var Users map[int64]*Account = map[int64]*Account{
	1: {
		ID:   1,
		Name: "Groot",
		Key:  "iamgroot",
	},
	2: {
		ID:   2,
		Name: "Thanos",
		Key:  "thanosdidnothingwrong",
	},
	3: {
		ID:   3,
		Name: "Hulk",
		Key:  "arrrr",
	},
}

List of user's account in the system.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID   int64
	Name string
	Key  string // The Key to authenticate user during handshake.
}

Account represent an example of internal user in the system.

Directories

Path Synopsis
cmd
client
Program client provide an example of chat client that connect to WebSocket server.
Program client provide an example of chat client that connect to WebSocket server.
server
Program server provide an example of WebSocket server as group chat.
Program server provide an example of WebSocket server as group chat.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL