-
Notifications
You must be signed in to change notification settings - Fork 48
Allow sending and receiving messages over the same UDP socket #66
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ public class OSCPortInBuilder { | |
private SocketAddress local; | ||
private SocketAddress remote; | ||
private NetworkProtocol networkProtocol = NetworkProtocol.UDP; | ||
private Transport transport; | ||
|
||
private OSCPacketListener addDefaultPacketListener() { | ||
if (packetListeners == null) { | ||
|
@@ -37,6 +38,33 @@ private OSCPacketListener addDefaultPacketListener() { | |
} | ||
|
||
public OSCPortIn build() throws IOException { | ||
|
||
if (packetListeners == null) { | ||
addDefaultPacketListener(); | ||
} | ||
|
||
// If transport is set, other settings cannot be used | ||
if (transport != null) { | ||
if (remote != null) { | ||
throw new IllegalArgumentException( | ||
"Cannot use remote socket address / port in conjunction with transport object."); | ||
} | ||
|
||
if (local != null) { | ||
throw new IllegalArgumentException( | ||
"Cannot use local socket address / port in conjunction with transport object."); | ||
} | ||
|
||
if (parserBuilder != null) { | ||
throw new IllegalArgumentException( | ||
"Cannot use parserBuilder in conjunction with transport object."); | ||
} | ||
|
||
return new OSCPortIn( | ||
transport, packetListeners | ||
); | ||
} | ||
|
||
if (local == null) { | ||
throw new IllegalArgumentException( | ||
"Missing local socket address / port."); | ||
|
@@ -50,10 +78,6 @@ public OSCPortIn build() throws IOException { | |
parserBuilder = new OSCSerializerAndParserBuilder(); | ||
} | ||
|
||
if (packetListeners == null) { | ||
addDefaultPacketListener(); | ||
} | ||
|
||
return new OSCPortIn( | ||
parserBuilder, packetListeners, local, remote, networkProtocol | ||
); | ||
|
@@ -97,6 +121,11 @@ public OSCPortInBuilder setNetworkProtocol(final NetworkProtocol protocol) { | |
return this; | ||
} | ||
|
||
public OSCPortInBuilder setTransport(final Transport networkTransport) { | ||
transport = networkTransport; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No must, and I see it is the same in the other methods, which is probably why you did it this way, but I' rather do this as |
||
return this; | ||
} | ||
|
||
public OSCPortInBuilder setPacketListeners( | ||
final List<OSCPacketListener> listeners) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,32 @@ public class OSCPortOutBuilder { | |
private SocketAddress remote; | ||
private SocketAddress local; | ||
private NetworkProtocol networkProtocol = NetworkProtocol.UDP; | ||
private Transport transport; | ||
|
||
public OSCPortOut build() throws IOException { | ||
|
||
// If transport is set, other settings cannot be used | ||
if (transport != null) { | ||
if (remote != null) { | ||
throw new IllegalArgumentException( | ||
"Cannot use remote socket address / port in conjunction with transport."); | ||
} | ||
|
||
if (local != null) { | ||
throw new IllegalArgumentException( | ||
"Cannot use local socket address / port in conjunction with transport."); | ||
} | ||
|
||
if (serializerBuilder != null) { | ||
throw new IllegalArgumentException( | ||
"Cannot use serializerBuilder in conjunction with transport."); | ||
} | ||
|
||
return new OSCPortOut( | ||
transport | ||
); | ||
} | ||
|
||
if (remote == null) { | ||
throw new IllegalArgumentException( | ||
"Missing remote socket address / port."); | ||
|
@@ -74,4 +98,9 @@ public OSCPortOutBuilder setNetworkProtocol(final NetworkProtocol protocol) { | |
networkProtocol = protocol; | ||
return this; | ||
} | ||
|
||
public OSCPortOutBuilder setTransport(final Transport networkTransport) { | ||
transport = networkTransport; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (... same here) |
||
return this; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a
NullPointerException
not be more appropriate?