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
e53fd4aa
Commit
e53fd4aa
authored
6 years ago
by
Jackson, John (LT)
Browse files
Options
Downloads
Patches
Plain Diff
Hw3 submission
parent
8b18ba9b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
deliverables/src/MV3500Cohort2018JulySeptember/homework3/Jackson_UdpReceiver.java
+52
-0
52 additions, 0 deletions
...ohort2018JulySeptember/homework3/Jackson_UdpReceiver.java
with
52 additions
and
0 deletions
deliverables/src/MV3500Cohort2018JulySeptember/homework3/Jackson_UdpReceiver.java
0 → 100644
+
52
−
0
View file @
e53fd4aa
package
MV3500Cohort2018JulySeptember.homework3
;
import
java.io.*
;
import
java.net.*
;
/**
* An example of receiving UDP packets. Since very often both the
* sender and receiver are on the same host we use different ports
* for each. This prevents complaints from the localhost.
*
* @author mcgredo
*/
public
class
Jackson_UdpReceiver
{
public
static
final
int
SENDING_PORT
=
1414
;
public
static
final
int
RECEIVING_PORT
=
1415
;
public
static
final
String
DESINATION_HOST
=
"localhost"
;
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
[]
args
)
{
try
{
System
.
out
.
println
(
"UdpReceiver started..."
);
// Create a UDP socket
DatagramSocket
udpSocket
=
new
DatagramSocket
(
RECEIVING_PORT
);
// You need a new receiving packet to read from every packet received
while
(
true
)
{
byte
[]
receiveBuffer
=
new
byte
[
15000
];
DatagramPacket
receivePacket
=
new
DatagramPacket
(
receiveBuffer
,
receiveBuffer
.
length
);
udpSocket
.
receive
(
receivePacket
);
// Decode the contents by extracting the data from the packet
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
receivePacket
.
getData
());
DataInputStream
dis
=
new
DataInputStream
(
bais
);
// What happens if you read an integer? Two double values? ***
String
first
=
dis
.
readUTF
();
// alternatives: readFloat(); readInt(); dis.readUTF();
//String second = dis.readUTF();
System
.
out
.
println
(
first
);
// + " second value: " + second);
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Problem with UdpReceiver, see exception trace:"
);
System
.
out
.
println
(
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