-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (74 loc) · 1.98 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"image"
"image/jpeg"
"net"
"os"
"github.com/headblockhead/wavesharecloud"
)
const (
CONN_HOST = "0.0.0.0"
CONN_PORT = "6868"
CONN_TYPE = "tcp"
)
func main() {
// Listen for incoming connections.
l, err := net.Listen(CONN_TYPE, CONN_HOST+":"+CONN_PORT)
if err != nil {
fmt.Printf("Error listening for connections: %v", err)
os.Exit(1)
}
// Close the listener when the application closes.
defer l.Close()
fmt.Println("Listening on " + CONN_HOST + ":" + CONN_PORT)
for {
// Listen for an incoming connection.
conn, err := l.Accept()
if err != nil {
fmt.Printf("Error accepting a connection: %v", err)
os.Exit(1)
}
// Handle connections in a new goroutine.
go handleRequest(conn)
}
}
func handleRequest(conn net.Conn) {
fmt.Println("New connection from:", conn.RemoteAddr())
// Setting up the connection to the display.
lc := wavesharecloud.NewLoggingConn(conn, false)
// Creating the display. If a password is required to unlock the display, here is where you would enter it.
// This automatically unlocks the display when created.
// In this case, the display is not locked, so the password is not required.
display := wavesharecloud.NewDisplay(lc, "")
// Open the timages and decode them.
testPatternImage, err := openImage("testpattern.jpg")
if err != nil {
fmt.Printf("Error opening test pattern image: %v\n", err)
}
// Drawing the testpattern image to the display.
err = display.SendImage(testPatternImage)
if err != nil {
fmt.Printf("Error sending testpattern image: %v\n", err)
}
// Shutdown the display.
err = display.Shutdown()
if err != nil {
fmt.Printf("Error shutting down: %v\n", err)
}
// Close the connection.
display.Disconnect()
}
func openImage(path string) (img image.Image, err error) {
// Open an image and decode it.
imageFile, err := os.Open(path)
if err != nil {
return nil, err
}
defer imageFile.Close()
img, err = jpeg.Decode(imageFile)
if err != nil {
return nil, err
}
return img, nil
}