本文整理汇总了C#中Protocol.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Protocol.Close方法的具体用法?C# Protocol.Close怎么用?C# Protocol.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Protocol
的用法示例。
在下文中一共展示了Protocol.Close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: handleClient
/// <summary>
/// the basic client handler -- calls processor.process in a loop,
/// until the client disconnects
/// </summary>
/// <param name="processor">
/// the processor instance that represents the client
/// </param>
protected static void handleClient(Protocol.BaseProcessor processor)
{
try
{
while (true)
{
processor.process();
}
}
catch (EndOfStreamException)
{
// finish on EOF
}
catch (IOException)
{
// usually a "connection reset by peer" -- just clean up nicely,
// the connection is dead anyway
}
finally
{
processor.Close();
}
}
示例2: GetFile
public int GetFile(string remotePath, Stream stream)
{
try
{
Protocol p = new Protocol();
p.Connect(this.serverAddress, this.port);
Message.MessageRequestGet req = new Message.MessageRequestGet();
req.Path = remotePath;
req.RequestId = Guid.NewGuid().ToString().Replace("-", "");
p.Send<Message.MessageRequestGet>(Message.MessageRequestGet.SerializeToBytes(req));
var msg = p.Receive();
long offset = 0;
float progress = 0;
if (msg is Message.MessageToken)
{
var tokens = msg as Message.MessageToken;
int count = tokens.Address.Count;
for (int i = 0; i < tokens.Address.Count; i++)
{
stream.Position = tokens.Offset[i];
Protocol srv = new Protocol();
srv.Connect(tokens.Address[i], port);
long size_left = tokens.Size[i];
long pos = 0;
long package_size = 1024 * 1024;
while (size_left > 0)
{
package_size = size_left > package_size ? package_size : size_left;
Message.MessageGet msgGet = new Message.MessageGet();
msgGet.Index = tokens.Index[i];
msgGet.Token = tokens.Token[i];
msgGet.Offset = pos;
msgGet.Size = package_size;
srv.Send<Message.MessageGet>(Message.MessageGet.SerializeToBytes(msgGet));
var reply = srv.Receive() as Message.MessageBlockData;
if (reply != null)
{
stream.Write(reply.Data, 0, (int)reply.Size);
}
pos += reply.Size;
offset += reply.Size;
size_left -= reply.Size;
}
srv.Close();
progress = (float)(1+i) / (float)tokens.Address.Count;
if( this.GetProgressCB!=null)
{
this.GetProgressCB((int)(progress * 100.0f), null);
}
}
}
else if (msg is Message.MessageActionError)
{
Message.MessageActionError err = msg as Message.MessageActionError;
if (this.GetProgressCB != null)
{
this.GetProgressCB(100, err.Message);
}
return 1;
}
}
catch(Exception eee)
{
if (this.GetProgressCB != null)
{
this.GetProgressCB(100, eee.Message);
}
}
return 0;
}