Re: [xSocket-develop] Data Handling
Status: Inactive
Brought to you by:
grro
|
From: Gregor R. <gre...@go...> - 2007-10-31 16:37:44
|
Hi,
xSocket doesn't force a request-response communication model.
The call back methods of the Handler (IDataHandler, IConnectHandler, =85) j=
ust
notifies that something is happened. That means if you have a connection
instance you can send and read data at anytime. Please note, that the
connection instance is not thread save. By sharing the same connection by
several threads you have to synchronize the access.
May the following example helps, to clarify things
Gregor
Example: server accepts incoming connections and starts a timer task to sen=
d
periodically data to the client
client Side
=3D=3D=3D=3D=3D=3D=3D=3D
IBlockingConnection con =3D new BlockingConnection(host, port);
while (true) {
String data =3D con.readStringByDelimiter("\r\n");
System.out.println(data);
}
server side
=3D=3D=3D=3D=3D=3D=3D=3D
IMultithreadedServer server =3D new MultithreadedServer(new Handler());
StreamUtils.start(server);
class Handler implements IConnectHandler {
private Timer timer =3D new Timer();
public boolean onConnect(INonBlockingConnection connection) throws
IOException {
// create a sender task and let it perform by the timer
timer.schedule(new SenderTask(connection), 1000, 1000);
return true;
}
class SenderTask extends TimerTask {
private INonBlockingConnection connection =3D null;
public SenderTask(INonBlockingConnection connection) {
this.connection =3D connection;
}
public void run() {
try {
connection.write("pong\r\n");
} catch (Exception e) {
e.printStackTrace();
}
}
}
2007/10/31, Eugen <pi...@de...>:
>
> Hi.. i want to ask how can I send data to a client without replying to
> some of its messages ( aka I want to send data whenever I like... )
>
> --
> [ =D0=80=C3=86H-=A7quad ]
> ']['][-][=80 F=87=D8=A7'][' =D8=D5[=A5]=C3]\[=87=C3]\[ ']['=80=C3[=A5]=
=87]\[ =D0=C7++
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
|