grim/gousb2snes
Clone
Summary
Browse
Changes
Graph
Update the package path for the new repository host
draft
default
tip
2020-04-27, Gary Kramlich
2bff12a54574
Update the package path for the new repository host
package
network
import
(
"encoding/binary"
"fmt"
"net"
)
const
(
packetSize
=
16
)
type
Client
struct
{
connection
net
.
Conn
running
bool
}
func
NewClient
(
c
net
.
Conn
)
*
Client
{
return
&
Client
{
connection
:
c
,
running
:
false
,
}
}
func
(
c
*
Client
)
Run
(
errChan
chan
error
)
{
c
.
running
=
true
defer
func
()
{
c
.
running
=
false
c
.
connection
.
Close
()
}()
for
{
if
!
c
.
running
{
break
}
packet
:=
[]
byte
{}
n
,
err
:=
c
.
connection
.
Read
(
packet
)
if
err
!=
nil
{
errChan
<-
err
return
}
if
n
!=
packetSize
{
errChan
<-
fmt
.
Errorf
(
"read %d bytes expected %d"
,
n
,
packetSize
)
return
}
typ
:=
binary
.
BigEndian
.
Uint32
(
packet
[
0
:])
release
:=
binary
.
BigEndian
.
Uint32
(
packet
[
4
:])
address
:=
binary
.
BigEndian
.
Uint32
(
packet
[
8
:])
fmt
.
Printf
(
"type: %v, release: %v, address: %v\n"
,
typ
,
release
,
address
)
}
}
func
(
c
*
Client
)
Close
()
{
c
.
running
=
false
}