资源简介

socket服务端采用SuperSocket搭建,客户端与服务端进行连接及向服务端发送消息,服务端使用业务向客户端发送消息进行通信

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace superSocketClient
{
    class Program
    {
        static Socket socketClient { get; set; }
        static void Main(string[] args)
        {
            //创建实例
            socketClient = new Socket(SocketType.Stream ProtocolType.Tcp);
            IPAddress ip = IPAddress.Parse(“127.0.0.1“);
            IPEndPoint point = new IPEndPoint(ip 2018);
            try
            {
                //进行连接
                socketClient.Connect(point);
                //不停的接收服务器端发送的消息
                Thread thread = new Thread(Recive);
                thread.IsBackground = true;
                thread.Start();
                ////不停的给服务器发送数据
                Thread thread2 = new Thread(Send);
                thread2.IsBackground = true;
                thread2.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine(“连接服务器失败 --- “ + ex.Message);
            }
            Console.ReadKey();
        }

        /// 
        /// 接收消息
        /// 

        /// 
        static void Recive()
        {
            //  为什么用telnet客户端可以,但这个就不行。
            while (true)
            {
                //获取发送过来的消息
                byte[] buffer = new byte[1024 * 1024 * 2];
                var effective = socketClient.Receive(buffer);
                if (effective == 0)
                {
                    break;
                }
                var str = Encoding.UTF8.GetString(buffer 0 effective);
                Console.WriteLine(“来自服务器 --- “ + str);
                Thread.Sleep(1000);
            }
        }


        static void Send()
        {
            int i = 0;
            //SignResult
            var sendStr = “SignResult 15023399108 \r\n“;
            var buffter = Encoding.UTF8.GetBytes(sendStr);
            var temp = socketClient.Send(buffter);
            Console.WriteLine(sendStr);

            //ADD
            sendStr = “ADD 1 2 \r\n“;
            buffter = Encoding.UTF8.GetBytes(sendStr);
            temp = socketClient.Send(buffter);
            Console.WriteLine(sendStr);
            

        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-18 10:54  superSocketServer\
     目录           0  2018-08-17 17:22  superSocketServer\.vs\
     目录           0  2018-08-17 17:22  superSocketServer\.vs\superSocketServer\
     目录           0  2018-08-17 17:22  superSocketServer\.vs\superSocketServer\v14\
     文件       52736  2018-08-18 12:32  superSocketServer\.vs\superSocketServer\v14\.suo
     目录           0  2018-08-17 17:32  superSocketServer\packages\
     目录           0  2018-08-17 17:23  superSocketServer\packages\log4net.2.0.3\
     目录           0  2018-08-17 17:23  superSocketServer\packages\log4net.2.0.3\lib\
     目录           0  2018-08-17 17:23  superSocketServer\packages\log4net.2.0.3\lib\net10-full\
     文件      299008  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net10-full\log4net.dll
     文件     1432719  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net10-full\log4net.xml
     目录           0  2018-08-17 17:23  superSocketServer\packages\log4net.2.0.3\lib\net11-full\
     文件      299008  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net11-full\log4net.dll
     文件     1433870  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net11-full\log4net.xml
     目录           0  2018-08-17 17:23  superSocketServer\packages\log4net.2.0.3\lib\net20-full\
     文件      303104  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net20-full\log4net.dll
     文件     1452231  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net20-full\log4net.xml
     目录           0  2018-08-17 17:23  superSocketServer\packages\log4net.2.0.3\lib\net35-client\
     文件      307200  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net35-client\log4net.dll
     文件     1506806  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net35-client\log4net.xml
     目录           0  2018-08-17 17:23  superSocketServer\packages\log4net.2.0.3\lib\net35-full\
     文件      311296  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net35-full\log4net.dll
     文件     1517265  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net35-full\log4net.xml
     目录           0  2018-08-17 17:23  superSocketServer\packages\log4net.2.0.3\lib\net40-client\
     文件      299520  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net40-client\log4net.dll
     文件     1506806  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net40-client\log4net.xml
     目录           0  2018-08-17 17:23  superSocketServer\packages\log4net.2.0.3\lib\net40-full\
     文件      301056  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net40-full\log4net.dll
     文件     1517265  2013-11-23 10:04  superSocketServer\packages\log4net.2.0.3\lib\net40-full\log4net.xml
     文件     1931465  2018-08-17 17:23  superSocketServer\packages\log4net.2.0.3\log4net.2.0.3.nupkg
     目录           0  2018-08-17 17:23  superSocketServer\packages\SuperSocket.1.6.6.1\
............此处省略117个文件信息

评论

共有 条评论