Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCP support (take 2) #42

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6978b4b
add NetworkProtocol, Client.networkProtocol that defaults to UDP
daveyarwood Nov 23, 2019
1797219
add Server.networkProtocol, NewServer constructor that defaults netwo…
daveyarwood Nov 23, 2019
1af7230
WIP send/receive test; implement receiving TCP packet on the server side
daveyarwood Nov 23, 2019
f7cf869
test sending and receiving a packet too large for UDP
daveyarwood Nov 23, 2019
ccb4667
fix test so that it propagates client send errors
daveyarwood Nov 24, 2019
ce6b523
for TCP, use ioutil.ReadAll, since we don't know the packet size and …
daveyarwood Nov 24, 2019
d3abe21
improve/fix NewClient and NewServer docstrings
daveyarwood Nov 24, 2019
bdf2feb
add client.laddrTCP; adjust SetLocalAddr to set laddrTCP when the pro…
daveyarwood Nov 24, 2019
f79e90b
fix/improve test error message
daveyarwood Nov 24, 2019
0f5a2db
document why the UDP test only sends a string of length 500
daveyarwood Nov 24, 2019
a1a5612
use a 1,000,000 byte string for the TCP test
daveyarwood Nov 24, 2019
cad5813
implement TCP sending on the client side
daveyarwood Nov 24, 2019
750795b
document use of TCP
daveyarwood Nov 25, 2019
1e1356a
mention TCP support in README
daveyarwood Nov 25, 2019
e255750
use `port` instead of hard-coded 6677 in one place I missed
daveyarwood Nov 25, 2019
760ff36
refactor TestServerMessageDispatching in order to test TCP; handle er…
daveyarwood Nov 25, 2019
d0cdbed
tests should propagate errors immediately instead of logging them and…
daveyarwood Nov 25, 2019
baf2e0b
implement server.ServeTCP; augment & refactor tests a bit
daveyarwood Nov 25, 2019
0589c1e
add mechanism for closing server connection; refactor test code to us…
daveyarwood Nov 25, 2019
1e0bc13
ensure that ListenAndServe closes its connection when done
daveyarwood Nov 25, 2019
a9950d0
make CloseConnection idempotent / nil-safe
daveyarwood Nov 25, 2019
2bd0f80
implement TCP in ListenAndServe
daveyarwood Nov 25, 2019
7e38197
use a 1,000,000 byte string for the TCP test
daveyarwood Nov 25, 2019
cbf35e4
Merge remote-tracking branch 'origin/master' into tcp-support
daveyarwood Dec 6, 2019
f18edda
adjust examples/client/client.go to generate random packets with nest…
daveyarwood Jan 12, 2020
8973d7b
fix typo
daveyarwood Jan 12, 2020
90bad45
adjust dispatching_server to allow setting the network protocol
daveyarwood Jan 12, 2020
9bd7cb2
implement String() on NetworkProtocol
daveyarwood Jan 12, 2020
7d349fa
support reading 'N' (null) arguments
daveyarwood Jan 12, 2020
64360b3
fix references to Timetag that should be *Timetag
daveyarwood Jan 12, 2020
87688fa
basic_server updates: support setting protocol; print nested packets
daveyarwood Jan 12, 2020
b645a08
bugfix: correctly handle padding 0-bytes at the end of a packet
daveyarwood Jan 13, 2020
3d015df
Revert "bugfix: correctly handle padding 0-bytes at the end of a packet"
daveyarwood Jan 16, 2020
7b957ff
Merge branch 'master' into tcp-support
daveyarwood Jan 17, 2020
c60efee
fix inadvertent syntax error
daveyarwood Jan 17, 2020
3525c23
Use functional options for protocol selection
glynternet Feb 27, 2020
0d5fecc
pass error through as the return value of s.CloseConnection
daveyarwood Feb 28, 2020
7d5ed2e
rename Option => ServerOption in preparation for ClientOption
daveyarwood Feb 28, 2020
ee682ad
collapse private UDP/TCP receive packet functions into the implementa…
daveyarwood Feb 29, 2020
d63ce05
fix doc references to osc.WithProtocol
daveyarwood Feb 29, 2020
dbf3c45
add doc comment for *server.Serve
daveyarwood Feb 29, 2020
4d54797
rename WithProtocol => ServerProtocol in preparation for ClientProtocol
daveyarwood Feb 29, 2020
4e71bc3
be consistent about not prefixing funcs in doc comments with "osc."
daveyarwood Feb 29, 2020
0675d0a
refactor client using functional options
daveyarwood Feb 29, 2020
24f2d85
Merge branch 'randomized-string-tests' into tcp-support-2
daveyarwood Mar 9, 2020
9da33ad
Merge branch 'tcp-support' into tcp-support-2
daveyarwood Mar 9, 2020
93478a0
Fix the number of arguments expected by the server and client demos
daveyarwood Feb 10, 2021
b69b5ee
Fix the number of arguments expected by the client and server examples
daveyarwood Feb 10, 2021
017ebb1
Merge branch 'randomized-string-tests' into tcp-support-2
daveyarwood Aug 15, 2021
11a612f
Merge branch 'master' into tcp-support-2
daveyarwood Jan 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@

## Features

- OSC Bundles, including timetags
- OSC Messages
- OSC Client
- OSC Server
- Supports the following OSC argument types:
- 'i' (Int32)
- 'f' (Float32)
- 's' (string)
- 'b' (blob / binary data)
- 'h' (Int64)
- 't' (OSC timetag)
- 'd' (Double/int64)
- 'T' (True)
- 'F' (False)
- 'N' (Nil)
- Support for OSC address pattern including '\*', '?', '{,}' and '[]' wildcards
- UDP (default) or TCP
- OSC Bundles, including timetags
- OSC Messages
- OSC Client
- OSC Server
- Supports the following OSC argument types:
- 'i' (Int32)
- 'f' (Float32)
- 's' (string)
- 'b' (blob / binary data)
- 'h' (Int64)
- 't' (OSC timetag)
- 'd' (Double/int64)
- 'T' (True)
- 'F' (False)
- 'N' (Nil)
- Support for OSC address pattern including '\*', '?', '{,}' and '[]' wildcards

## Install

Expand Down
22 changes: 18 additions & 4 deletions examples/basic_server/basic_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (Debugger) Dispatch(packet osc.Packet) {
}

func printUsage() {
fmt.Printf("Usage: %s PORT\n", os.Args[0])
fmt.Printf("Usage: %s PROTOCOL PORT\n", os.Args[0])
}

func main() {
Expand All @@ -80,7 +80,19 @@ func main() {
os.Exit(1)
}

port, err := strconv.ParseInt(os.Args[1], 10, 32)
var protocol osc.NetworkProtocol
switch strings.ToLower(os.Args[1]) {
case "udp":
protocol = osc.UDP
case "tcp":
protocol = osc.TCP
default:
fmt.Println("Invalid protocol: " + os.Args[1])
printUsage()
os.Exit(1)
}

port, err := strconv.ParseInt(os.Args[2], 10, 32)
if err != nil {
fmt.Println(err)
printUsage()
Expand All @@ -89,10 +101,12 @@ func main() {

addr := fmt.Sprintf("127.0.0.1:%d", port)

server := &osc.Server{Addr: addr, Dispatcher: Debugger{}}
server := osc.NewServer(addr, Debugger{}, 0,
// defaults to UDP if not used
osc.ServerProtocol(protocol))

fmt.Println("### Welcome to go-osc receiver demo")
fmt.Printf("Listening via UDP on port %d...\n", port)
fmt.Printf("Listening via %s on port %d...\n", protocol, port)

if err := server.ListenAndServe(); err != nil {
fmt.Println(err)
Expand Down
18 changes: 15 additions & 3 deletions examples/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func randomBundle() *osc.Bundle {
}

func printUsage() {
fmt.Printf("Usage: %s PORT\n", os.Args[0])
fmt.Printf("Usage: %s PROTOCOL PORT\n", os.Args[0])
}

func main() {
Expand All @@ -86,15 +86,27 @@ func main() {
os.Exit(1)
}

port, err := strconv.ParseInt(os.Args[1], 10, 32)
var protocol osc.NetworkProtocol
switch strings.ToLower(os.Args[1]) {
case "udp":
protocol = osc.UDP
case "tcp":
protocol = osc.TCP
default:
fmt.Println("Invalid protocol: " + os.Args[1])
printUsage()
os.Exit(1)
}

port, err := strconv.ParseInt(os.Args[2], 10, 32)
if err != nil {
fmt.Println(err)
printUsage()
os.Exit(1)
}

ip := "localhost"
client := osc.NewClient(ip, int(port))
client := osc.NewClient(ip, int(port), osc.ClientProtocol(protocol))

fmt.Println("### Welcome to go-osc transmitter demo")
fmt.Println("Please, select the OSC packet type you would like to send:")
Expand Down
64 changes: 56 additions & 8 deletions examples/dispatching_server/dispatching_server.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,66 @@
package main

import "github.com/hypebeast/go-osc/osc"
import (
"fmt"
"math/rand"
"os"
"strconv"
"strings"
"time"

"github.com/hypebeast/go-osc/osc"
)

func printUsage() {
fmt.Printf("Usage: %s PROTOCOL PORT\n", os.Args[0])
}

func main() {
addr := "127.0.0.1:8765"
rand.Seed(time.Now().Unix())

numArgs := len(os.Args[1:])

if numArgs != 2 {
printUsage()
os.Exit(1)
}

var protocol osc.NetworkProtocol
switch strings.ToLower(os.Args[1]) {
case "udp":
protocol = osc.UDP
case "tcp":
protocol = osc.TCP
default:
fmt.Println("Invalid protocol: " + os.Args[1])
printUsage()
os.Exit(1)
}

port, err := strconv.ParseInt(os.Args[2], 10, 32)
if err != nil {
fmt.Println(err)
printUsage()
os.Exit(1)
}

addr := fmt.Sprintf("127.0.0.1:%d", port)

d := osc.NewStandardDispatcher()
d.AddMsgHandler("/message/address", func(msg *osc.Message) {

if err := d.AddMsgHandler("/message/address", func(msg *osc.Message) {
osc.PrintMessage(msg)
})
server := &osc.Server{
Addr: addr,
Dispatcher: d,
}); err != nil {
fmt.Println(err)
os.Exit(1)
}

server.ListenAndServe()
server := osc.NewServer(addr, d, 0, osc.ServerProtocol(protocol))

fmt.Printf("Listening via %s on port %d...\n", protocol, port)

if err := server.ListenAndServe(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
14 changes: 8 additions & 6 deletions osc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Features:
- OSC bundles, including timetags
- Support for OSC address pattern including '*', '?', '{,}' and '[]' wildcards

This OSC implementation uses the UDP protocol for sending and receiving
OSC packets.
This OSC implementation supports using UDP or TCP as the protocol for sending
and receiving OSC packets. UDP is used by default.

The unit of transmission of OSC is an OSC Packet. Any application that sends
OSC Packets is an OSC Client; any application that receives OSC Packets is
Expand Down Expand Up @@ -58,6 +58,8 @@ Usage
OSC client example:

client := osc.NewClient("localhost", 8765)
// To use TCP instead of UDP:
// client := osc.NewClient("localhost", 8765, osc.ClientProtocol(osc.TCP))
msg := osc.NewMessage("/osc/address")
msg.Append(int32(111))
msg.Append(true)
Expand All @@ -72,10 +74,10 @@ OSC server example:
osc.PrintMessage(msg)
})

server := &osc.Server{
Addr: addr,
Dispatcher:d,
}
server := osc.NewServer(addr, d, 0)
// To use TCP instead of UDP:
// server := osc.NewServer(addr, d, 0, osc.ServerProtocol(osc.TCP))

server.ListenAndServe()
*/
package osc
Loading