首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# Tcp传输 不稳定 是不是小弟我的消息太大

2012-07-30 
C# Tcp传输 不稳定 是不是我的消息太大?我的消息类如下:C# codeusing Systemusing System.Collections.Ge

C# Tcp传输 不稳定 是不是我的消息太大?
我的消息类如下:

C# code
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace NetLib{    [Serializable]    public class NetMsg    {        #region 常量定义        public const string ALL_PEOPLE = "/all";        public const int BUFFER_SIZE = 4000;        public const int OPR_MOV = 0;        public const int OPR_CREATE = 1;        public const int OPR_START_MOV = 2;        public const int OPR_DESTROY = 3;        public const int OPR_LOST_BLOOD = 4;        public const int OPR_STOP_MOV = 5;        public const int OPR_TURN=6;        public const int LOGIN = 7;        public const int LOGOUT = 8;        public const int ROOM_APPLY = 9;        public const int ROOM_ENTER = 10;        public const int OPR_CHAT=11;        public const int ROOM_CREATE=12;        public const int MAX_ROOM = 13;        public const int MAX_USER = 14;        public const int ROOM_FULL = 15;        public const int ROOMS_INFO=16;        public const int USERS_INFO=17;        public const int LOGIN_OK = 18;        public const int LOGIN_FAIL = 19;        public const int CONNECTED = 20;        public const int IMALIVE=21;//心跳包        public const int REG_APPLY = 22;        public const int OPR_SENDIP = 23;        public const int ROOM_EXIT = 24;        public const int OPR_UR_MASTER = 25;//你是房主         public const int OPR_START_GAME = 26;//进入游戏        public const int OPR_PREPARE = 27;//准备消息         public const int OPR_CAN_START = 28;//可以开始游戏        public const int REG_OK = 29;        public const int REG_FAIL = 30;        public const int OPR_FIRE = 31;        public const int TYPE_TANK = 32;        public const int TYPE_MISSILE = 33;        public const int TYPE_BASE = 34;        public const int TYPE_BLAST = 35;        public const int OPR_STARTED = 36;        #endregion 常量定义结束        public int roomNumber;        public int clientID;        public int operation;        public int objType;        public int objNumber;        public int locationX;        public int locationY;        public int direction;        public int addtionInt;        public string addtionInfo;//额外信息,如发送的消息、ip地址等等        public int receiverID;        public List<String> setValues;        public string username;        public string password;    }}

我是直接通过BinnaryFormatter序列化后直接发送,接收到后反序列化的,不知道是不是消息太大了,反正连接过程中不稳定,经常没有响应。
求指导!!!

[解决办法]
public List<String> setValues; 这个内容多的话会超过socket默认的buffer, 8192bytes,所以需要接收完整个数据再反序列化
[解决办法]
不要用序列化,序列化有很多问题,对于引用,比如你的 List<String> setValues,.net处理起来很麻烦,效率很低,你的这个数据不大,但序列化出来的数据可能会很大,

所以你最好自己写序列化方法,

[解决办法]
探讨
我是直接通过BinnaryFormatter序列化后直接发送,接收到后反序列化的,不知道是不是消息太大了,反正连接过程中不稳定,经常没有响应。

[解决办法]
试一下就知道了,

探讨


我也是觉得,没有多少消息,出来就400多byte了,就算一个纯新建的消息也要430多,如果自己写的话,一个游戏消息差不多能压缩到30byte或者更……

[解决办法]
探讨

引用:
引用:
我是直接通过BinnaryFormatter序列化后直接发送,接收到后反序列化的,不知道是不是消息太大了,反正连接过程中不稳定,经常没有响应。


看不出怎样会“消息太大”。局域网上发送几M大的消息也许会觉得“卡”,但是也是看不出什么“没有响应”问题的。100%是你通讯程序问题。


你好,我的通讯程序大致是这样的:
服务端用定时接……

热点排行