• 大小: 159KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: C#
  • 标签: Socket  WPF  

资源简介

WPF实现CS结构,基于socket连接,实现ServerClient发送消息

资源截图

代码片段和文件信息

using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace CSockets
{
    public class CClientSocket
    {
        #region Delegates
        public delegate void ConnectionDelegate(Socket soc);
        public delegate void ErrorDelegate(string ErroMessage Socket soc int ErroCode);
        #endregion

        #region Events
        public event ConnectionDelegate OnConnect;
        public event ConnectionDelegate OnDisconnect;
        public event ConnectionDelegate OnRead;
        public event ConnectionDelegate OnWrite;
        public event ErrorDelegate onerror;
        public event ConnectionDelegate OnSendFile;
        #endregion

        #region Variables
        private AsyncCallback WorkerCallBack;
        private Socket mainSocket = new Socket(AddressFamily.InterNetwork SocketType.Stream ProtocolType.Tcp);
        private IPEndPoint serverEndPoint;
        private byte[] dataBuffer = new byte[1024];
        private int mPort = 0;
        private byte[] mBytesReceived;
        private string mTextReceived = ““;
        private string mTextSent = ““;
        private string mRemoteAddress = ““;
        private string mRemoteHost = ““;
        #endregion

        #region Propetiers
        /// 
        /// Port to connect to server
        /// 

        public int Port
        {
            get
            {
                return (mPort);
            }
        }

        /// 
        /// Bytes received by the Socket
        /// 

        public byte[] ReceivedBytes
        {
            get
            {
                byte[] temp = null;
                if(mBytesReceived != null)
                {
                    temp = mBytesReceived;
                    mBytesReceived = null;
                }
                return (temp);
            }
        }

        /// 
        /// Message received by the Socket
        /// 

        public string ReceivedText
        {
            get
            {
                string temp = mTextReceived;
                mTextReceived = ““;
                return (temp);
            }
        }

        /// 
        /// Message send by the Socket
        /// 

        public string WriteText
        {
            get
            {
                string temp = mTextSent;
                mTextSent = ““;
                return (temp);
            }
        }

        /// 
        /// IP Server
        /// 

        public string RemoteAddress
        {
            get
            {
                if(mainSocket.Connected)
                    return (mRemoteAddress);
                else
                    return ““;
            }
        }

        /// 
        /// Host Server
        /// 

        public string RemoteHost
        {
        

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      12582  2019-03-06 15:36  CSharpSocket - 基础连接\KPClient\CClientSocket.cs

     文件       2489  2019-03-06 10:56  CSharpSocket - 基础连接\KPClient\KPClient.csproj

     文件       1469  2019-03-05 16:47  CSharpSocket - 基础连接\KPClient\KPClient.sln

     文件        724  2019-03-06 13:04  CSharpSocket - 基础连接\KPClient\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6433  2019-03-06 15:36  CSharpSocket - 基础连接\KPClient\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        318  2019-03-06 15:36  CSharpSocket - 基础连接\KPClient\obj\Debug\KPClient.csproj.FileListAbsolute.txt

     文件       6291  2019-03-06 15:36  CSharpSocket - 基础连接\KPClient\obj\Debug\KPClient.csprojResolveAssemblyReference.cache

     文件      10752  2019-03-06 15:36  CSharpSocket - 基础连接\KPClient\obj\Debug\KPClient.dll

     文件      19968  2019-03-06 15:36  CSharpSocket - 基础连接\KPClient\obj\Debug\KPClient.pdb

     文件          0  2019-03-05 09:25  CSharpSocket - 基础连接\KPClient\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2019-03-05 09:25  CSharpSocket - 基础连接\KPClient\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2019-03-05 09:25  CSharpSocket - 基础连接\KPClient\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       6437  2019-03-06 11:03  CSharpSocket - 基础连接\KPClient\obj\Release\DesignTimeResolveAssemblyReferencesInput.cache

     文件        236  2019-03-06 11:03  CSharpSocket - 基础连接\KPClient\obj\Release\KPClient.csproj.FileListAbsolute.txt

     文件      10240  2019-03-06 11:03  CSharpSocket - 基础连接\KPClient\obj\Release\KPClient.dll

     文件      17920  2019-03-06 11:03  CSharpSocket - 基础连接\KPClient\obj\Release\KPClient.pdb

     文件          0  2019-03-06 10:43  CSharpSocket - 基础连接\KPClient\obj\Release\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2019-03-06 10:43  CSharpSocket - 基础连接\KPClient\obj\Release\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2019-03-06 10:43  CSharpSocket - 基础连接\KPClient\obj\Release\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       1324  2019-03-05 09:25  CSharpSocket - 基础连接\KPClient\Properties\AssemblyInfo.cs

     文件        184  2019-03-06 10:56  CSharpSocket - 基础连接\KPClientUI\App.config

     文件        374  2019-03-05 10:26  CSharpSocket - 基础连接\KPClientUI\App.xaml

     文件        337  2019-03-05 10:26  CSharpSocket - 基础连接\KPClientUI\App.xaml.cs

     文件       4778  2019-03-06 10:56  CSharpSocket - 基础连接\KPClientUI\KPClientUI.csproj

     文件       1467  2019-03-06 12:59  CSharpSocket - 基础连接\KPClientUI\KPClientUI.sln

     文件       2333  2019-03-06 11:04  CSharpSocket - 基础连接\KPClientUI\MainWindow.xaml

     文件       3260  2019-03-05 13:18  CSharpSocket - 基础连接\KPClientUI\MainWindow.xaml.cs

     文件       2337  2019-03-06 15:36  CSharpSocket - 基础连接\KPClientUI\obj\Debug\App.g.cs

     文件       2337  2019-03-06 15:36  CSharpSocket - 基础连接\KPClientUI\obj\Debug\App.g.i.cs

     文件        872  2019-03-06 13:28  CSharpSocket - 基础连接\KPClientUI\obj\Debug\DesignTimeResolveAssemblyReferences.cache

............此处省略139个文件信息

评论

共有 条评论