• 大小: 634KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-05-17
  • 语言: C#
  • 标签: Socket  C#  服务端  

资源简介

Socket通信含服务端、客户端、WebSocket,代码完整清晰

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using StriveEngine.Core;
using StriveEngine.Tcp.Passive;

namespace StriveEngine.SimpleDemoClient
{
    /*
    * 更多实用组件请访问 www.oraycn.com 或 QQ:168757008。
    * 
    * ESframework 强悍的通信框架、P2P框架、群集平台。OMCS 简单易用的网络语音视频框架。MFile 语音视频录制组件。StriveEngine 轻量级的通信引擎。
    */
    public partial class Form1 : Form
    {
        private ITcpPassiveEngine tcpPassiveEngine;
        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender EventArgs e)
        {
            try
            {
                //初始化并启动客户端引擎(TCP、文本协议)
                this.tcpPassiveEngine = NetworkEngineFactory.CreateTextTcpPassiveEngine(this.textBox_IP.Text int.Parse(this.textBox_port.Text) new DefaultTextContractHelper(“\0“));
                this.tcpPassiveEngine.MessageReceived += new CbDelegate(tcpPassiveEngine_MessageReceived);
                this.tcpPassiveEngine.AutoReconnect = true;//启动掉线自动重连                
                this.tcpPassiveEngine.ConnectionInterrupted += new CbDelegate(tcpPassiveEngine_ConnectionInterrupted);
                this.tcpPassiveEngine.ConnectionRebuildSucceed += new CbDelegate(tcpPassiveEngine_ConnectionRebuildSucceed);
                this.tcpPassiveEngine.Initialize();

                this.button2.Enabled = true;
                this.button3.Enabled = false;
                MessageBox.Show(“连接成功!“);
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }

        void tcpPassiveEngine_ConnectionRebuildSucceed()
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new CbDelegate(this.tcpPassiveEngine_ConnectionRebuildSucceed));
            }
            else
            {
                this.button2.Enabled = true;
                MessageBox.Show(“重连成功。“);
            }
        }

        void tcpPassiveEngine_ConnectionInterrupted()
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new CbDelegate(this.tcpPassiveEngine_ConnectionInterrupted));
            }
            else
            {
                this.button2.Enabled = false;
                MessageBox.Show(“您已经掉线。“);
            }
        }

        void tcpPassiveEngine_MessageReceived(System.Net.IPEndPoint serverIPE byte[] bMsg)
        {
            string msg = System.Text.Encoding.UTF8.GetString(bMsg); //消息使用UTF-8编码
            msg = msg.Substring(0 msg.Length - 1); //将结束标记“\0“剔除
            this.ShowMessage(msg);
        }       

        private void ShowMessage(string msg)
        {
            if (this.InvokeRequired)
            {
                this.Begi

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

     文件        518  2017-11-10 17:38  StriveEngine.SimpleDemo\Demo说明.txt

     文件     323584  2018-12-11 11:21  StriveEngine.SimpleDemo\Resources\StriveEngine.dll

     文件      70200  2018-12-11 11:21  StriveEngine.SimpleDemo\Resources\StriveEngine.xml

     文件       2626  2016-07-06 10:09  StriveEngine.SimpleDemo\StriveEngine.SimpleDemo.sln

    ..A..H.     59904  2018-12-11 11:23  StriveEngine.SimpleDemo\StriveEngine.SimpleDemo.suo

     文件     323584  2018-12-11 11:21  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\bin\Debug\StriveEngine.dll

     文件      13312  2018-12-11 11:23  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\bin\Debug\StriveEngine.SimpleDemoClient.exe

     文件      32256  2018-12-11 11:23  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\bin\Debug\StriveEngine.SimpleDemoClient.pdb

     文件      11608  2018-06-01 13:24  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\bin\Debug\StriveEngine.SimpleDemoClient.vshost.exe

     文件        490  2010-03-17 22:39  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\bin\Debug\StriveEngine.SimpleDemoClient.vshost.exe.manifest

     文件      70200  2018-12-11 11:21  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\bin\Debug\StriveEngine.xml

     文件       3884  2017-11-01 16:57  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\Form1.cs

     文件       9312  2013-06-02 10:45  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\Form1.Designer.cs

     文件       5817  2013-06-02 10:45  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\Form1.resx

     文件       5562  2018-12-11 11:23  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1774  2014-10-31 15:11  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\ResGen.read.1.tlog

     文件       2098  2014-10-31 15:11  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\ResGen.write.1.tlog

     文件        998  2013-06-02 10:31  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\StriveEngine.SimpleDemo.csproj.FileListAbsolute.txt

     文件      26112  2013-06-02 10:30  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\StriveEngine.SimpleDemo.pdb

     文件        180  2013-06-01 11:35  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\StriveEngine.SimpleDemo.Properties.Resources.resources

     文件      17114  2018-12-11 11:23  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\StriveEngine.SimpleDemoClient.csproj.FileListAbsolute.txt

     文件        975  2018-06-01 12:57  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\StriveEngine.SimpleDemoClient.csproj.GenerateResource.Cache

     文件      10406  2018-12-11 11:23  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\StriveEngine.SimpleDemoClient.csprojResolveAssemblyReference.cache

     文件      13312  2018-12-11 11:23  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\StriveEngine.SimpleDemoClient.exe

     文件        180  2018-12-11 11:23  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\StriveEngine.SimpleDemoClient.Form1.resources

     文件      32256  2018-12-11 11:23  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\StriveEngine.SimpleDemoClient.pdb

     文件        180  2018-12-11 11:23  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\StriveEngine.SimpleDemoClient.Properties.Resources.resources

     文件       4608  2013-06-02 10:36  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\obj\x86\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        643  2014-10-31 15:11  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\Program.cs

     文件       1408  2013-06-02 10:42  StriveEngine.SimpleDemo\StriveEngine.SimpleDemoClient\Properties\AssemblyInfo.cs

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

评论

共有 条评论