|
|
ISocketService implementation: - JSP/Java
|
Views : 461
|
|
Tagged in : JSP-Java
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
public class SimpleEchoService : ISocketService
{
public void OnConnected(ConnectionEventArgs e)
{
//----- Check the host!
if (e.Connection.HostType == HostType.htServer)
{
//----- Enqueue receive!
e.Connection.BeginReceive();
}
else
{
//----- Enqueue send a custom message!
byte[] b =
GetMessage(e.Connection.SocketHandle.ToInt32());
e.Connection.BeginSend(b);
}
}
public void OnSent(MessageEventArgs e)
{
//----- Check the host. In this case both start a receive!
if (e.Connection.HostType == HostType.htServer)
{
//----- Enqueue receive!
e.Connection.BeginReceive();
}
else
{
//----- Enqueue receive!
e.Connection.BeginReceive();
}
}
public override void OnReceived(MessageEventArgs e)
{
//----- Check the host!
if (e.Connection.HostType == HostType.htServer)
{
//----- If server, send the data buffer received!
byte[] b = e.Buffer;
e.Connection.BeginSend(b);
}
else
{
//----- If client, generate another
//----- custom message and send it!
byte[] b = GetMessage(e.Connection.SocketHandle.ToInt32());
e.Connection.BeginSend(b);
}
}
public override void OnDisconnected(DisconnectedEventArgs e)
{
//----- Check the host!
if (e.Connection.HostType == HostType.htServer)
{
//----- Nothing!
}
else
{
//----- Reconnect with server!
e.Connection.AsClientConnection().BeginReconnect();
}
}
} |
|
By gowtham, On - 2010-02-09 |
|
|
|