networkComms.net2.3.1开源版本,基于gpl V3协议。因为不能公开3.x版本的源码,所以基于此版本进行学习。3.X版本进行了诸多改进和Bug修复,使用方法上两者相差不大。
/*请注意使用以下代码,需遵循GplV3协议*/
#if WINDOWS_PHONE
#else
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
#if ANDROID
using PreserveAttribute = Android.Runtime.PreserveAttribute;
#elif iOS
using PreserveAttribute = MonoTouch.Foundation.PreserveAttribute;
#endif
namespace DPSBase
{
/// .net自带的序列化器
/// </summary>
[DataSerializerProcessor(2)]
public class BinaryFormaterSerializer : DataSerializer
{
static DataSerializer instance;
[Obsolete("Instance access via class obsolete, use DPSManager.GetSerializer<T>")]
public static DataSerializer Instance
{
get
{
if (instance == null)
instance = GetInstance<BinaryFormaterSerializer>();
return instance;
}
}
#if ANDROID || iOS
[Preserve]
#endif
private BinaryFormaterSerializer() { }
#region ISerialize Members
/// <inheritdoc />
/// 把对象序列化为二进制数据
protected override void SerialiseDataObjectInt(Stream ouputStream, object objectToSerialise, Dictionary<string, string> options)
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(ouputStream, objectToSerialise);
ouputStream.Seek(0, 0);
}
/// <inheritdoc />
/// 把二进制数据序列化为对象
protected override object DeserialiseDataObjectInt(Stream inputStream, Type resultType, Dictionary<string, string> options)
{
BinaryFormatter formatter = new BinaryFormatter();
return formatter.Deserialize(inputStream);
}
#endregion
}
}
#endif
http://www.cnblogs.com/networkcomms
http://www.networkcoms.cn 编辑
来自英国剑桥的c#网络通讯框架 开源版本: networkcomms2.3.1 可以进入此页面下载 networkcomms网络通讯框架学习
【开源下载】基于TCP网络通信的即时聊天系统(IM系统)(c#源码)
[源码下载]Demo2.模拟简单登陆-效果图 基于networkcomms2.3.1
[源码下载]Demo1 客户端从服务器获取信息(基于networkcomms2.3.1)
【开源下载】基于TCP网络通信的自动升级程序c#源码