Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
WS4D
jCoAP
Commits
ad0847be
Commit
ad0847be
authored
May 31, 2015
by
Bjoern Konieczek
Browse files
Enable actual multicast processing
parent
08690603
Changes
13
Hide whitespace changes
Inline
Side-by-side
ws4d-jcoap-applications/src/org/ws4d/coap/client/BasicCoapBlockClient.java
View file @
ad0847be
...
...
@@ -56,4 +56,9 @@ public class BasicCoapBlockClient implements CoapClient {
System
.
out
.
println
(
response
.
toString
());
System
.
out
.
println
(
new
String
(
response
.
getPayload
()));
}
@Override
public
void
onMCResponse
(
CoapClientChannel
channel
,
CoapResponse
response
,
InetAddress
srcAddress
,
int
srcPort
)
{
System
.
out
.
println
(
"Received response"
);
}
}
ws4d-jcoap-applications/src/org/ws4d/coap/client/BasicCoapClient.java
View file @
ad0847be
...
...
@@ -105,4 +105,9 @@ public class BasicCoapClient implements CoapClient {
public
void
onResponse
(
CoapClientChannel
channel
,
CoapResponse
response
)
{
System
.
out
.
println
(
"Received response"
);
}
@Override
public
void
onMCResponse
(
CoapClientChannel
channel
,
CoapResponse
response
,
InetAddress
srcAddress
,
int
srcPort
)
{
System
.
out
.
println
(
"Received response"
);
}
}
ws4d-jcoap-applications/src/org/ws4d/coap/proxy/CoapClientProxy.java
View file @
ad0847be
...
...
@@ -18,6 +18,8 @@
*/
package
org.ws4d.coap.proxy
;
import
java.net.InetAddress
;
import
org.apache.log4j.Logger
;
import
org.ws4d.coap.connection.BasicCoapChannelManager
;
import
org.ws4d.coap.interfaces.CoapClient
;
...
...
@@ -77,4 +79,9 @@ public class CoapClientProxy implements CoapClient{
}
}
@Override
public
void
onMCResponse
(
CoapClientChannel
channel
,
CoapResponse
response
,
InetAddress
srcAddress
,
int
srcPort
)
{
System
.
out
.
println
(
"Received Response"
);
}
}
ws4d-jcoap-applications/src/org/ws4d/coap/proxy/CoapServerProxy.java
View file @
ad0847be
...
...
@@ -154,6 +154,11 @@ public class CoapServerProxy implements CoapServer{
public
void
onSeparateResponseFailed
(
CoapServerChannel
channel
)
{
// TODO Auto-generated method stub
}
@Override
public
void
onReset
(
CoapRequest
lastRequest
)
{
System
.
out
.
println
(
"Received RST message"
);
}
}
ws4d-jcoap-applications/src/org/ws4d/coap/server/SeparateResponseCoapServer.java
View file @
ad0847be
...
...
@@ -80,5 +80,10 @@ public class SeparateResponseCoapServer implements CoapServer {
System
.
out
.
println
(
"Separate Response failed"
);
}
@Override
public
void
onReset
(
CoapRequest
lastRequest
)
{
System
.
out
.
println
(
"Received RST message"
);
}
}
ws4d-jcoap-plugtest/src/org/ws4d/coap/test/PlugtestClient.java
View file @
ad0847be
...
...
@@ -220,4 +220,10 @@ public class PlugtestClient implements CoapClient{
System
.
exit
(
0
);
}
}
@Override
public
void
onMCResponse
(
CoapClientChannel
channel
,
CoapResponse
response
,
InetAddress
srcAddress
,
int
srcPort
)
{
System
.
out
.
println
(
"Received Multicast Response"
);
}
}
\ No newline at end of file
ws4d-jcoap/src/org/ws4d/coap/connection/BasicCoapClientChannel.java
View file @
ad0847be
...
...
@@ -139,6 +139,35 @@ public class BasicCoapClientChannel extends BasicCoapChannel implements CoapClie
/* normal or separate response */
client
.
onResponse
(
this
,
(
BasicCoapResponse
)
message
);
}
@Override
public
void
handleMCResponse
(
CoapMessage
message
,
InetAddress
srcAddress
,
int
srcPort
)
{
if
(
message
.
isRequest
()){
/* this is a client channel, no requests allowed */
message
.
getChannel
().
sendMessage
(
new
CoapEmptyMessage
(
CoapPacketType
.
RST
,
message
.
getMessageID
()));
return
;
}
if
(
message
.
isEmpty
()
&&
message
.
getPacketType
()
==
CoapPacketType
.
ACK
){
/* this is the ACK of a separate response */
//TODO: implement a handler or listener, that informs a client when a sep. resp. ack was received
return
;
}
if
(
message
.
getPacketType
()
==
CoapPacketType
.
CON
)
{
/* this is a separate response */
/* send ACK */
this
.
sendMessage
(
new
CoapEmptyMessage
(
CoapPacketType
.
ACK
,
message
.
getMessageID
()));
}
if
(
message
.
getBlock1
()
!=
null
||
message
.
getBlock2
()
!=
null
){
//TODO: handle blockwise multicast transactions
System
.
err
.
println
(
"ERROR: Received a blockwise response to a multicast request!"
);
}
else
{
client
.
onMCResponse
(
this
,
(
BasicCoapResponse
)
message
,
srcAddress
,
srcPort
);
}
}
@Override
public
void
lostConnection
(
boolean
notReachable
,
boolean
resetByServer
)
{
...
...
ws4d-jcoap/src/org/ws4d/coap/connection/BasicCoapMulticastChannel.java
deleted
100755 → 0
View file @
08690603
/* Copyright 2015 University of Rostock
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
package
org.ws4d.coap.connection
;
import
java.io.IOException
;
import
java.net.DatagramPacket
;
import
java.net.InetAddress
;
import
java.net.MulticastSocket
;
import
java.net.UnknownHostException
;
import
org.ws4d.coap.interfaces.CoapChannel
;
import
org.ws4d.coap.interfaces.CoapMessage
;
import
org.ws4d.coap.messages.CoapBlockOption.CoapBlockSize
;
public
class
BasicCoapMulticastChannel
implements
CoapChannel
{
private
MulticastSocket
multicastSocket
=
null
;
private
int
port
=
0
;
private
InetAddress
multicastAddress
=
null
;
public
BasicCoapMulticastChannel
(
String
multicastAddress
,
int
port
)
throws
UnknownHostException
{
this
.
multicastAddress
=
InetAddress
.
getByName
(
multicastAddress
);
this
.
port
=
port
;
}
public
void
init
()
{
try
{
this
.
multicastSocket
=
new
MulticastSocket
(
this
.
port
);
this
.
multicastSocket
.
setReuseAddress
(
true
);
this
.
multicastSocket
.
setSoTimeout
(
15000
);
this
.
multicastSocket
.
joinGroup
(
multicastAddress
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Error occured: "
+
e
.
getMessage
());
return
;
}
}
@Override
public
void
sendMessage
(
CoapMessage
msg
)
{
try
{
DatagramPacket
p
=
new
DatagramPacket
(
msg
.
serialize
(),
msg
.
serialize
().
length
);
this
.
multicastSocket
.
send
(
p
);
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Error occured: "
+
e
.
getMessage
());
return
;
}
}
@Override
public
void
close
()
{
this
.
multicastSocket
.
close
();
}
@Override
public
InetAddress
getRemoteAddress
()
{
return
this
.
multicastAddress
;
}
@Override
public
int
getRemotePort
()
{
return
this
.
port
;
}
@Override
public
void
handleMessage
(
CoapMessage
message
)
{
// TODO Auto-generated method stub
}
@Override
public
void
lostConnection
(
boolean
notReachable
,
boolean
resetByServer
)
{
// TODO Auto-generated method stub
}
@Override
public
CoapBlockSize
getMaxReceiveBlocksize
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
void
setMaxReceiveBlocksize
(
CoapBlockSize
maxReceiveBlocksize
)
{
// TODO Auto-generated method stub
}
@Override
public
CoapBlockSize
getMaxSendBlocksize
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
void
setMaxSendBlocksize
(
CoapBlockSize
maxSendBlocksize
)
{
// TODO Auto-generated method stub
}
}
ws4d-jcoap/src/org/ws4d/coap/connection/BasicCoapServerChannel.java
View file @
ad0847be
...
...
@@ -123,6 +123,11 @@ public class BasicCoapServerChannel extends BasicCoapChannel implements CoapServ
}
}
@Override
public
void
handleMCResponse
(
CoapMessage
message
,
InetAddress
srcAddress
,
int
srcPort
)
{
System
.
err
.
println
(
"ERROR: Received a response on a Server"
);
};
/*TODO: implement */
public
void
lostConnection
(
boolean
notReachable
,
boolean
resetByServer
){
server
.
onSeparateResponseFailed
(
this
);
...
...
ws4d-jcoap/src/org/ws4d/coap/connection/BasicCoapSocketHandler.java
View file @
ad0847be
...
...
@@ -345,6 +345,10 @@ public class BasicCoapSocketHandler implements CoapSocketHandler {
if
(
!
mcResp
)
{
logger
.
warn
(
"Could not find channel of incomming response: message dropped"
);
return
;
}
else
{
msg
.
setChannel
(
channel
);
channel
.
handleMCResponse
(
msg
,
addr
.
getAddress
(),
addr
.
getPort
()
);
return
;
}
}
...
...
ws4d-jcoap/src/org/ws4d/coap/interfaces/CoapChannel.java
View file @
ad0847be
...
...
@@ -53,6 +53,14 @@ public interface CoapChannel {
* @param message - the message to be handled
*/
public
void
handleMessage
(
CoapMessage
message
);
/**
* handles an incoming multicast response
* @param message - the message to be handled
* @param srcAddress - the source address of the multicast response
* @param srcPort - the source port of the multicast response
*/
public
void
handleMCResponse
(
CoapMessage
message
,
InetAddress
srcAddress
,
int
srcPort
);
/* TODO: implement Error Type */
/**
...
...
ws4d-jcoap/src/org/ws4d/coap/interfaces/CoapClient.java
View file @
ad0847be
...
...
@@ -15,6 +15,8 @@
package
org.ws4d.coap.interfaces
;
import
java.net.InetAddress
;
/**
* @author Christian Lerche <christian.lerche@uni-rostock.de>
*/
...
...
@@ -26,6 +28,15 @@ public interface CoapClient extends CoapChannelListener {
* @param response - The {@link CoapResponse} that arrived.
*/
public
void
onResponse
(
CoapClientChannel
channel
,
CoapResponse
response
);
/**
* This is a callback method which allows to handle a response to a multicast request at the application layer.
* @param channel - The CoapClientChannel where the message arrived.
* @param resonse - The CoapResponse that arrived
* @param srcAddress - The IP address of the origin server of the response.
* @param srcPort - The Port of the origin server.
*/
public
void
onMCResponse
(
CoapClientChannel
channel
,
CoapResponse
response
,
InetAddress
srcAddress
,
int
srcPort
);
/**
* This is a callback method which allows to handle a connection failure at the application layer.
...
...
ws4d-jcoap/src/org/ws4d/coap/test/InterfaceTest.java
View file @
ad0847be
...
...
@@ -33,7 +33,7 @@ import org.ws4d.coap.rest.CoapResourceServer;
/**
* Tests for jCoAP.
*
* @author Bjrn Butzin <bjoern.butzin[at]uni-rostock.de>
* @author Bj
�
rn Butzin <bjoern.butzin[at]uni-rostock.de>
*/
public
class
InterfaceTest
{
...
...
@@ -48,6 +48,11 @@ public class InterfaceTest {
public
void
onResponse
(
CoapClientChannel
channel
,
CoapResponse
response
)
{
// This is intended to be empty
}
@Override
public
void
onMCResponse
(
CoapClientChannel
channel
,
CoapResponse
response
,
InetAddress
srcAddress
,
int
srcPort
)
{
// This is intended to be empty
}
@Override
public
void
onConnectionFailed
(
CoapClientChannel
channel
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment