本文整理汇总了C#中ISender.Send方法的典型用法代码示例。如果您正苦于以下问题:C# ISender.Send方法的具体用法?C# ISender.Send怎么用?C# ISender.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISender
的用法示例。
在下文中一共展示了ISender.Send方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleData
public void HandleData(MemBlock packet, ISender from, object node)
{
_message_count++;
long stop_time, rt_ticks = -10000;
if ( !from.Equals(node)) {
if (packet[0] == 0) {
//log.Debug("Echo Response:");
stop_time = System.DateTime.Now.Ticks;
int received_uid = NumberSerializer.ReadInt(packet, 1);
if(uid_starttime.ContainsKey(received_uid)){
rt_ticks = stop_time - (long)EchoTester.uid_starttime[received_uid];
}
double rt_ms = (double) rt_ticks/10000.0;
uid_brunetpingtime.Add(received_uid, rt_ms);
Console.WriteLine("Packet ID = {0}, Round-trip = {1}", received_uid, rt_ms);
}
else {
//log.Debug("Echo Request:");
}
//log.Debug(packet.ToString());
//System.Console.WriteLine("{0}", packet.ToString());
if (packet[0] > 0) {
//Send a reply back, this is a request
byte[] new_payload = new byte[ packet.Length ];
packet.CopyTo(new_payload, 0);
new_payload[0] = (byte) 0;
from.Send(new CopyList(PType.Protocol.Echo, MemBlock.Reference(new_payload)));
}
}
}
示例2: HandleData
public void HandleData(MemBlock b, ISender return_path, object state) {
byte b0 = b[0];
if( b0 == 0 ) {
//This is a request:
MemBlock data = b.Slice(1);
//Make sure node to reply with a zero
return_path.Send( new CopyList( PType.Protocol.Echo, REPLY_HEADER, data) );
}
}
示例3: HandleData
public void HandleData(MemBlock data, ISender return_path, object state)
{
/*
* Write the messages:
*/
Console.WriteLine("Msg from: {0}", return_path);
data.ToMemoryStream().WriteTo( System.Console.OpenStandardOutput() );
Console.WriteLine();
return_path.Send( new CopyList(PType.Protocol.Chat, MemBlock.Null) );
}
示例4: HandleData
public void HandleData(MemBlock p, ISender edge, object state)
{
try {
int num = NumberSerializer.ReadInt(p, 0);
Console.WriteLine("Got packet number: {0}", num);
edge.Send( p );
}
catch(Exception x) {
Console.WriteLine("Server got exception on send: {0}", x);
}
}
示例5: HandleData
/**
* When requests come in this handles it
*/
public void HandleData(MemBlock payload, ISender ret_path, object state)
{
Exception exception = null;
#if RPC_DEBUG
Console.Error.WriteLine("[RpcServer: {0}] Getting method invocation request at: {1}.",
_rrman.Info, DateTime.Now);
#endif
try {
object data = AdrConverter.Deserialize(payload);
IList l = data as IList;
if( l == null ) {
//We could not cast the request into a list... so sad:
throw new AdrException(-32600,"method call not a list");
}
string methname = (string)l[0];
#if RPC_DEBUG
Console.Error.WriteLine("[RpcServer: {0}] Getting invocation request, method: {1}",
_rrman.Info, methname);
#endif
/*
* Lookup this method name in our table.
* This uses a cache, so it should be fast
* after the first time
*/
IRpcHandler handler = null;
string mname = null;
lock( _sync ) {
object[] info = (object[]) _method_cache[methname];
if( info == null ) {
int dot_idx = methname.IndexOf('.');
if( dot_idx == -1 ) {
throw new AdrException(-32601, "No Handler for method: " + methname);
}
string hname = methname.Substring(0, dot_idx);
//Skip the '.':
mname = methname.Substring(dot_idx + 1);
handler = (IRpcHandler)_method_handlers[ hname ];
if( handler == null ) {
//No handler for this.
throw new AdrException(-32601, "No Handler for method: " + methname);
}
info = new object[2];
info[0] = handler;
info[1] = mname;
_method_cache[ methname ] = info;
}
else {
handler = (IRpcHandler)info[0];
mname = (string)info[1];
}
}
ArrayList pa = (ArrayList)l[1];
#if DAVID_ASYNC_INVOKE
object[] odata = new object[4];
odata[0] = handler;
odata[1] = ret_path;
odata[2] = mname;
odata[3] = pa;
_rpc_command.Enqueue(odata);
#else
handler.HandleRpc(ret_path, mname, pa, ret_path);
#endif
}
catch(ArgumentException argx) {
exception = new AdrException(-32602, argx);
}
catch(TargetParameterCountException argx) {
exception = new AdrException(-32602, argx);
}
catch(Exception x) {
exception = x;
}
if (exception != null) {
//something failed even before invocation began
#if RPC_DEBUG
Console.Error.WriteLine("[RpcServer: {0}] Something failed even before invocation began: {1}",
_rrman.Info, exception);
#endif
using( MemoryStream ms = new MemoryStream() ) {
AdrConverter.Serialize(exception, ms);
ret_path.Send( new CopyList( PType.Protocol.Rpc, MemBlock.Reference( ms.ToArray() ) ) );
}
}
}
示例6: HandleRequest
protected void HandleRequest(ReqrepType rt, int idnum,
MemBlock rest, ISender retpath)
{
/**
* Lets see if we have been asked this question before
*/
ReplyState rs = null;
bool resend = false;
#if REQREP_DEBUG
Console.Error.WriteLine("[ReqrepManager: {0}] Receiving request id: {1}, from: {2}",
_info, idnum, retpath);
#endif
RequestKey rk = new RequestKey(idnum, retpath);
lock( _sync ) {
rs = (ReplyState)_reply_cache[rk];
if( rs == null ) {
rs = GenerateReplyState(_prefix, rk);
}
else {
resend = true;
}
}
if( resend ) {
//This is an old request:
rs.Resend();
}
else {
//This is a new request:
try {
_sub.Handle(rest, rs);
}
catch {
lock( _sync ) {
ReleaseReplyState(rs);
}
//This didn't work out:
try {
MemBlock err_data = MemBlock.Reference(
new byte[]{ (byte) ReqrepError.HandlerFailure } );
ICopyable reply = MakeRequest(ReqrepType.Error, idnum, err_data);
retpath.Send(reply);
}
catch {
//If this fails, we may think about logging.
//The return path could fail, that's the only obvious exception
///@todo log exception
}
}
}
}
示例7: HandleControlConfirm
/// <summary>3b) Receive a Confirm, verify the entire stack and send a Confirm
/// 4a)Receive a Confirm, verify the entire stack and all set to go</summary>
/// <param name="sa">A security association that we wish to perform the
/// specified control operation on.</param>
/// <param name="scm">The received SecurityControlMessage.</param>
/// <param name="scm_reply">A prepared reply message (with headers and such.</param>
/// <param name="return_path">Where to send the result.</param>
/// <param name="low_level_sender">We expect the return_path to not be an edge or
/// some other type of "low level" sender, so this contains the parsed out value.</param>
protected void HandleControlConfirm(PeerSecAssociation sa,
SecurityControlMessage scm, SecurityControlMessage scm_reply,
ISender return_path, ISender low_level_sender)
{
ProtocolLog.WriteIf(ProtocolLog.Security, GetHashCode() + " Received Confirm from: " + low_level_sender);
if(sa == null) {
throw new Exception("No valid SA!");
}
HashAlgorithm sha1 = new SHA1CryptoServiceProvider();
scm.Verify((RSACryptoServiceProvider) sa.RemoteCertificate.RSA, sha1);
if(return_path == low_level_sender) {
sa.VerifyResponse(scm.Hash);
} else {
sa.VerifyRequest(scm.Hash);
scm_reply.LocalCookie = scm.RemoteCookie;
scm_reply.RemoteCookie = scm.LocalCookie;
scm_reply.Hash = sa.DHEWithCertificateAndCAsInHash.Value;
scm_reply.Type = SecurityControlMessage.MessageType.Confirm;
lock(_private_key_lock) {
scm_reply.Sign(_private_key, sha1);
}
ICopyable to_send = new CopyList(SecureControl, scm_reply.Packet);
return_path.Send(to_send);
}
sa.Enable();
ProtocolLog.WriteIf(ProtocolLog.Security, GetHashCode() + " Successful Confirm from: " + low_level_sender);
}
示例8: HandleControlDHEWithCertificateAndCAs
/// <summary>2b) Receive a DHEWithCertificateAndCAs, verify the certificate and attempt
/// to find a matching Certificate for the list of CAs, if you find one,
/// finish the DHE handshake and send the certificate via a DHEWithCertificate</summary>
/// <param name="sa">A security association that we wish to perform the
/// specified control operation on.</param>
/// <param name="scm">The received SecurityControlMessage.</param>
/// <param name="scm_reply">A prepared reply message (with headers and such.</param>
/// <param name="return_path">Where to send the result.</param>
/// <param name="low_level_sender">We expect the return_path to not be an edge or
/// some other type of "low level" sender, so this contains the parsed out value.</param>
protected void HandleControlDHEWithCertificateAndCAs(PeerSecAssociation sa,
SecurityControlMessage scm, SecurityControlMessage scm_reply,
ISender return_path, ISender low_level_sender)
{
ProtocolLog.WriteIf(ProtocolLog.Security, GetHashCode() + " Received DHEWithCertificateAndCAs from: " + low_level_sender);
if(sa == null) {
sa = CreateSecurityAssociation(low_level_sender, scm.SPI, false);
}
byte[] cert = new byte[scm.Certificate.Length];
scm.Certificate.CopyTo(cert, 0);
X509Certificate rcert = new X509Certificate(cert);
_ch.Verify(rcert, low_level_sender);
HashAlgorithm sha1 = new SHA1CryptoServiceProvider();
scm.Verify((RSACryptoServiceProvider) rcert.RSA, sha1);
X509Certificate lcert = null;
if(SecurityPolicy.GetPolicy(scm.SPI).PreExchangedKeys) {
lcert = _ch.DefaultCertificate;
} else {
lcert = _ch.FindCertificate(scm.CAs);
}
sa.LocalCertificate = lcert;
sa.RemoteCertificate = rcert;
sa.RDHE.Value = scm.DHE;
sa.DHEWithCertificateAndCAsInHash.Value = MemBlock.Reference(sha1.ComputeHash((byte[]) scm.Packet));
scm_reply.LocalCookie = scm.RemoteCookie;
scm_reply.RemoteCookie = scm.LocalCookie;
scm_reply.DHE = sa.LDHE;
scm_reply.Certificate = MemBlock.Reference(lcert.RawData);
scm_reply.Type = SecurityControlMessage.MessageType.DHEWithCertificate;
lock(_private_key_lock) {
scm_reply.Sign(_private_key, sha1);
}
sa.DHEWithCertificateHash.Value = MemBlock.Reference(sha1.ComputeHash((byte[]) scm_reply.Packet));
ICopyable to_send = new CopyList(SecureControl, scm_reply.Packet);
return_path.Send(to_send);
ProtocolLog.WriteIf(ProtocolLog.Security, GetHashCode() + " Successful DHEWithCertificateAndCAs from: " + low_level_sender);
}
示例9: HandleControlCookie
/// <summary>1b) Receive a Cookie which responds with a CookieResponse</summary>
/// <param name="sa">A security association that we wish to perform the
/// specified control operation on.</param>
/// <param name="calc_cookie">Cookie value for the association sender.</param>
/// <param name="scm">The received SecurityControlMessage.</param>
/// <param name="scm_reply">A prepared reply message (with headers and such.</param>
/// <param name="return_path">Where to send the result.</param>
/// <param name="low_level_sender">We expect the return_path to not be an edge or
/// some other type of "low level" sender, so this contains the parsed out value.</param>
protected void HandleControlCookie(PeerSecAssociation sa,
MemBlock calc_cookie, SecurityControlMessage scm,
SecurityControlMessage scm_reply, ISender return_path,
ISender low_level_sender)
{
ProtocolLog.WriteIf(ProtocolLog.Security, String.Format(
"{0}, Received Cookie from: {1}, In-Cookie: {2}",
GetHashCode(), low_level_sender, scm.LocalCookie));
scm_reply.Type = SecurityControlMessage.MessageType.CookieResponse;
scm_reply.RemoteCookie = scm.LocalCookie;
scm_reply.LocalCookie = calc_cookie;
if(SecurityPolicy.GetPolicy(scm.SPI).PreExchangedKeys) {
scm_reply.CAs = new List<MemBlock>(0);
} else {
scm_reply.CAs = _ch.SupportedCAs;
}
ICopyable to_send = new CopyList(SecureControl, scm_reply.Packet);
return_path.Send(to_send);
ProtocolLog.WriteIf(ProtocolLog.Security, String.Format(
"{0}, Successful Cookie from: {1}, Out-Cookie: {2}",
GetHashCode(), low_level_sender, calc_cookie));
}
示例10: NoSuchSA
/// <summary>After a restart of the Security system, one guy may think
/// we still have an association and there will be no way for him to know
/// that our side is broken, unless we notify him as such. We notify him
/// by sending this packet. How he deals with that is up to him.</summary>
protected void NoSuchSA(int spi, ISender remote_sender) {
SecurityControlMessage scm_reply = new SecurityControlMessage();
scm_reply.Version = Version;
scm_reply.SPI = spi;
scm_reply.Type = SecurityControlMessage.MessageType.NoSuchSA;
ICopyable to_send = new CopyList(Security, SecureControl, scm_reply.Packet);
remote_sender.Send(to_send);
}
示例11: Transmit
/// <summary>
/// Transmit Messages from queue to Server
/// </summary>
void Transmit()
{
try
{
UInt32 iSequenceNo = 0;
Byte bSequenceNo;
Logger.Info("EventTransmitter: STARTING");
_Message = new QueueManager(Settings.EventTransmitterSourceQ);
//Getting mode of transfer
_Sender = SenderFactory.GetSender();
if (this.InitializeWithRetry())
{
_Message.OpenQueue();
while (!_evtTransmitShutDown.WaitOne(10))
{
Int32 iResponse;
try
{
_IsTransmitting = true;
if (iSequenceNo >= 255)
{
iSequenceNo = 1;
}
else
{
iSequenceNo++;
}
bSequenceNo = Convert.ToByte(iSequenceNo);
Logger.Info("Reading queue");
if (!_Message.IsQueueOpen)
{
_Message.OpenQueue();
}
strXML = _Message.ReadMessage();
Logger.Info("Read Complete");
SendToExternalLog("SENDING: " + strXML);
// parse return message
//Construct STM format message
// Refresh or empty message
if (string.IsNullOrEmpty(strXML))
{
Logger.Debug("Either Queue refresh or no message received.");
continue;
}
_MessageFormatter = FormatFactory.GetFormatter(strXML, true);
Logger.Debug("Event Request SeqNo[" + iSequenceNo.ToString() + "]" + _MessageFormatter.MessageStream);
}
catch (MessageFilteredException MesEx)
{
Logger.Error("EventTransmitter", "Transmit", MesEx.Message);
Logger.Info("EventTransmitter", "Transmit", "Committing Queue[Filtered Message]");
_Message.Commit();
continue;
}
catch (Exception Ex)
{
Logger.Error("EventTransmitter", "Transmit", Ex);
Logger.Info("EventTransmitter", "Transmit", "Error in message:" + strXML);
if (Settings.DeleteMessageOnParseErr == 1)
{
Logger.Error("EventTransmitter", "Transmit", "Committing Queue[DeleteMessageOnParseErr]");
_Message.Commit();
continue;
}
_evtTransmitShutDown.WaitOne(5000);
}
int iRetryOnNWErr = 0;
do
{
if (_evtTransmitShutDown.WaitOne(50))
{
break;
}
try
{
if (iRetryOnNWErr >= Settings.iMaxTransmissionRetry)
{
//Close transmission when maximum retry reached
throw new Exception(String.Format("Stopping Transmision after Retrying [{0}] times. ", iRetryOnNWErr.ToString()));
}
else
{
//transmit message to server
iResponse = _Sender.Send(_MessageFormatter);
//.........这里部分代码省略.........
示例12: SenderStage
/// <summary>
/// This stage is different in that the <see cref="AbstractStage.RootPath"/> for this class is actually an archive file name.
/// </summary>
public SenderStage(string archiveFilename, ISender sender, CancellationToken cancellationToken)
: base(archiveFilename, "Sending the report", ReportStageType.Sending, cancellationToken, pc => sender.Send(archiveFilename, cancellationToken, pc))
{
}