日期:2014-05-17  浏览次数:21030 次

C#网络通信 在XP下能正常通信,但换Win7却不能通信
麻烦各位帮我看一下啊 
在XP下能正常通信啊,换Win7却不行了
TcpSend函数还是正常的,但是TcpReceive不能重复接收,问题出在哪里呢?
是Thread.Sleep延时的问题吗? 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace Network {
    public class TcpClient {
        private Socket _Socket = null;  //定义Socket
        private IPEndPoint ipEndPoint = null; //定义IP端口

        public byte[] buffer = new byte[1];  //字符缓冲区

        public bool IsConnected { //判断网络是否已连接
            get {
                if (_Socket == null) {
                    return false;
                }
                return true;
            }
        }

        public TcpClient() {
            
        }

        public TcpClient(DataStructure.IPContext _ipContext) {
            InitSocket(_ipContext.Ip, _ipContext.Port);  //调用初始化Socket函数
        }

        public TcpClient(IPAddress _ip, int _port) {
            InitSocket(_ip, _port);  //调用初始化Socket函数
        }

        public void InitSocket(IPAddress _ip, int _port) {  //初始化Socket
            ipEndPoint = new IPEndPoint(_ip, _port);
            _Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);  //TCP Socket
            _Socket.SendTimeout = 2000;  //发送时间
            _Socket.ReceiveTimeout = 3000;  //接收时间
            _Socket.ReceiveBufferSize = 1;  //缓冲区大小
        }

        /*
         * 连接初始化后的_Socket
         * 连接成功返回true
         * 连接失败返回false