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
df08db7a
Commit
df08db7a
authored
5 years ago
by
J. M. Bailey
Browse files
Options
Downloads
Patches
Plain Diff
Add close method
parent
003f9b50
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/edu/nps/moves/dis7/util/DisNetworking.java
+27
-11
27 additions, 11 deletions
src/edu/nps/moves/dis7/util/DisNetworking.java
with
27 additions
and
11 deletions
src/edu/nps/moves/dis7/util/DisNetworking.java
+
27
−
11
View file @
df08db7a
...
@@ -54,30 +54,44 @@ public class DisNetworking
...
@@ -54,30 +54,44 @@ public class DisNetworking
return
MCAST_GROUP
;
return
MCAST_GROUP
;
}
}
public
void
stop
()
{
if
(
rsocket
!=
null
)
{
rsocket
.
close
();
rsocket
=
null
;
}
if
(
ssocket
!=
null
)
{
ssocket
.
close
();
ssocket
=
null
;
}
}
public
Pdu
receivePdu
()
throws
IOException
public
Pdu
receivePdu
()
throws
IOException
{
{
PduFactory
pduFactory
=
new
PduFactory
();
PduFactory
pduFactory
=
new
PduFactory
();
BuffAndLength
blen
=
receiveRawPdu
();
BuffAndLength
blen
=
receiveRawPdu
();
return
pduFactory
.
createPdu
(
blen
.
buff
);
return
pduFactory
.
createPdu
(
blen
.
buff
);
}
}
private
MulticastSocket
rsocket
;
public
BuffAndLength
receiveRawPdu
()
throws
IOException
public
BuffAndLength
receiveRawPdu
()
throws
IOException
{
{
MulticastSocket
socket
;
DatagramPacket
packet
;
DatagramPacket
packet
;
socket
=
new
MulticastSocket
(
DIS_PORT
);
r
socket
=
new
MulticastSocket
(
DIS_PORT
);
InetAddress
maddr
=
InetAddress
.
getByName
(
MCAST_GROUP
);
InetAddress
maddr
=
InetAddress
.
getByName
(
MCAST_GROUP
);
socket
.
setNetworkInterface
(
findIp4Interface
());
r
socket
.
setNetworkInterface
(
findIp4Interface
());
socket
.
joinGroup
(
maddr
);
r
socket
.
joinGroup
(
maddr
);
byte
buffer
[]
=
new
byte
[
MAX_DIS_PDU_SIZE
];
byte
buffer
[]
=
new
byte
[
MAX_DIS_PDU_SIZE
];
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
);
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
);
//System.out.println("Listening on " + MCAST_GROUP + ":" + DIS_PORT + " if:" + socket.getNetworkInterface().getDisplayName());
//System.out.println("Listening on " + MCAST_GROUP + ":" + DIS_PORT + " if:" + socket.getNetworkInterface().getDisplayName());
socket
.
receive
(
packet
);
//blocks here waiting for next DIS pdu to be received on broadcast IP and specified port
r
socket
.
receive
(
packet
);
//blocks here waiting for next DIS pdu to be received on broadcast IP and specified port
//System.out.println("packet received from " + packet.getSocketAddress());
//System.out.println("packet received from " + packet.getSocketAddress());
socket
.
close
();
rsocket
.
close
();
rsocket
=
null
;
return
new
BuffAndLength
(
packet
.
getData
(),
packet
.
getLength
());
return
new
BuffAndLength
(
packet
.
getData
(),
packet
.
getLength
());
}
}
...
@@ -91,17 +105,19 @@ public class DisNetworking
...
@@ -91,17 +105,19 @@ public class DisNetworking
sendRawPdu
(
baos
.
toByteArray
());
sendRawPdu
(
baos
.
toByteArray
());
}
}
MulticastSocket
ssocket
;
public
void
sendRawPdu
(
byte
[]
data
)
throws
IOException
public
void
sendRawPdu
(
byte
[]
data
)
throws
IOException
{
{
MulticastSocket
m
socket
=
new
MulticastSocket
();
s
socket
=
new
MulticastSocket
();
InetAddress
maddr
=
InetAddress
.
getByName
(
MCAST_GROUP
);
InetAddress
maddr
=
InetAddress
.
getByName
(
MCAST_GROUP
);
// load byte buffer into packet and send
// load byte buffer into packet and send
DatagramPacket
packet
=
new
DatagramPacket
(
data
,
data
.
length
,
maddr
,
DIS_PORT
);
DatagramPacket
packet
=
new
DatagramPacket
(
data
,
data
.
length
,
maddr
,
DIS_PORT
);
m
socket
.
setNetworkInterface
(
findIp4Interface
());
s
socket
.
setNetworkInterface
(
findIp4Interface
());
m
socket
.
send
(
packet
);
s
socket
.
send
(
packet
);
msocket
.
close
();
ssocket
.
close
();
ssocket
=
null
;
//System.out.println("sent to " + maddr.getHostAddress() + ":" + DIS_PORT);
//System.out.println("sent to " + maddr.getHostAddress() + ":" + DIS_PORT);
}
}
...
...
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