Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
3c21a197
Commit
3c21a197
authored
3 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
UdpSender is sending but not properly connecting to UdpReceiver, debugging in progress
parent
fcdc3758
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/src/UdpMulticastExamples/UdpReceiver.java
+8
-4
8 additions, 4 deletions
examples/src/UdpMulticastExamples/UdpReceiver.java
examples/src/UdpMulticastExamples/UdpSender.java
+9
-6
9 additions, 6 deletions
examples/src/UdpMulticastExamples/UdpSender.java
with
17 additions
and
10 deletions
examples/src/UdpMulticastExamples/UdpReceiver.java
+
8
−
4
View file @
3c21a197
...
...
@@ -9,7 +9,8 @@ import java.net.*;
* for each. This prevents collision complaints from the localhost.
*
* Start this before launching UdpSender.
*
*
* @see <a href=" https://docs.oracle.com/javase/tutorial/networking/datagrams/index.html"> https://docs.oracle.com/javase/tutorial/networking/datagrams/index.html</a>
* @see <a href="https://docs.oracle.com/javase/tutorial/essential/io/datastreams.html">https://docs.oracle.com/javase/tutorial/essential/io/datastreams.html</a>
* @see <a href="https://en.wikipedia.org/wiki/User_Datagram_Protocol">https://en.wikipedia.org/wiki/User_Datagram_Protocol</a>
* @author mcgredo
...
...
@@ -17,9 +18,9 @@ import java.net.*;
*/
public
class
UdpReceiver
{
// p
rivate
static final int SENDING_PORT = 1414; // port used by UdpSender, unneeded here
p
rivate
static
final
int
RECEIVING_PORT
=
1415
;
p
rivate
static
final
String
DESINATION_HOST
=
"localhost"
;
// p
ublic
static final int
SENDING_PORT = 1414;
// port used by UdpSender, unneeded here
p
ublic
static
final
int
RECEIVING_PORT
=
1415
;
// sharable
p
ublic
static
final
String
DES
T
INATION_HOST
=
"localhost"
;
/**
* Program invocation, execution starts here
...
...
@@ -38,6 +39,7 @@ public class UdpReceiver
udpSocket
=
new
DatagramSocket
(
RECEIVING_PORT
);
udpSocket
.
setReceiveBufferSize
(
1500
);
// how many bytes are in buffer? MTU=1500 is good
udpSocket
.
setBroadcast
(
false
);
// we're just receiving here
// udpSocket.setReuseAddress(true);
byte
[]
byteArray
=
new
byte
[
1500
];
DatagramPacket
receivePacket
=
new
DatagramPacket
(
byteArray
,
byteArray
.
length
);
...
...
@@ -58,6 +60,8 @@ public class UdpReceiver
packetCount
++;
// good practice to increment counter at start of loop, when possible
udpSocket
.
receive
(
receivePacket
);
// blocks until packet is received
System
.
out
.
println
(
"UdpReceiver address/port: "
+
udpSocket
.
getInetAddress
().
getHostAddress
()
+
"/"
+
RECEIVING_PORT
);
// values of interest follow. order and types of what was sent must match what you are reading!
firstInt
=
dis
.
readInt
();
// packetID
secondFloat
=
dis
.
readFloat
();
...
...
This diff is collapsed.
Click to expand it.
examples/src/UdpMulticastExamples/UdpSender.java
+
9
−
6
View file @
3c21a197
...
...
@@ -19,13 +19,14 @@ import java.net.*;
*/
public
class
UdpSender
{
p
rivate
static
final
String
MY_NAME
=
System
.
getProperty
(
"user.name"
);
// guru incantation 8)
// p
rivate
static final int SENDING_PORT = 1414; // not needed, can let system choose an open local port
p
rivate
static
final
int
RECEIVING_PORT
=
1415
;
p
rivate
static
final
int
TOTAL_PACKETS_TO_SEND
=
100
;
p
ublic
static
final
String
MY_NAME
=
System
.
getProperty
(
"user.name"
);
// guru incantation 8)
// p
ublic
static final int SENDING_PORT = 1414; // not needed, can let system choose an open local port
p
ublic
static
final
int
RECEIVING_PORT
=
UdpReceiver
.
RECEIVING_PORT
;
// 1415; ensure consistent
p
ublic
static
final
int
TOTAL_PACKETS_TO_SEND
=
100
;
public
static
final
String
DESTINATION_HOST
=
"localhost"
;
// here is what we need for lab comms
p
rivate
static
final
String
DESTINATION_HOST
=
"10.1.105.16"
;
// localhost 127.0.0.1 or argon 10.1.105.1 or 10.1.105.1 or whatever
//
p
ublic
static final String DESTINATION_HOST = "10.1.105.16"; // localhost 127.0.0.1 or argon 10.1.105.1 or 10.1.105.1 or whatever
/**
* Program invocation, execution starts here
...
...
@@ -67,6 +68,8 @@ public class UdpSender
InetAddress
sourceAddress
=
InetAddress
.
getByName
(
"localhost"
);
// possibly identical if source not modified
DatagramPacket
datagramPacket
=
new
DatagramPacket
(
byteArray
,
byteArray
.
length
,
destinationAddress
,
RECEIVING_PORT
);
System
.
out
.
println
(
"UdpSender address/port: "
+
destinationAddress
.
getHostAddress
()
+
"/"
+
RECEIVING_PORT
);
// Hmmm, how fast does UDP stream go? Does UDP effectively slow packets down, or does
// this cause network problems? (hint: yes for an unlimited send rate, unlike TCP).
...
...
@@ -100,7 +103,7 @@ public class UdpSender
" sent values("
+
packetID
+
","
+
value
+
",\""
+
message
+
"\","
+
isPacketIdEvenParity
+
")"
+
padding
+
" as packet #"
+
index
+
" of "
+
TOTAL_PACKETS_TO_SEND
);
baos
.
reset
();
// clear the output stream after sending
}
}
// end for loop
}
catch
(
IOException
|
InterruptedException
e
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment