• 大小: 0.04M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-04-30
  • 语言: C#
  • 标签: Socket  服务端  ck  OC  代码  

资源简介

socket服务端代码

资源截图

代码片段和文件信息

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 Socketdata
{
    class Program
    {
        static Socket serverSocket;
        static Socket clientSocket;
        static Thread thread;
            static void Main(string[] args)
        {
            IPEndPoint ipep = new IPEndPoint(IPAddress.Any 3001);
            serverSocket = new Socket(ipep.AddressFamily SocketType.Stream ProtocolType.Tcp);
            serverSocket.Bind(ipep);
            serverSocket.Listen(100);
            while (true)
            {
                clientSocket = serverSocket.Accept();
                thread = new Thread(new ThreadStart(dowork));
                thread.Start();
               // dowork();
            }


        }
        private static void dowork()
        {
            string str_message = ““;
            Socket s = clientSocket;//客户端信息 
            IPEndPoint ipEndPoint = (IPEndPoint)s.RemoteEndPoint;
            String address = ipEndPoint.Address.ToString();
            String port = ipEndPoint.Port.ToString();
            Console.WriteLine(address + “:“ + port + “ 连接过来了“);
            Byte[] inBuffer = new Byte[1024];
            Byte[] outBuffer = new Byte[1024];
            Byte[] outBuffer2 = new Byte[1024];
            try
            {
                //outBuffer2 = Encoding.ASCII.GetBytes(“你好,欢迎链接服务“);
                //var data = s.Send(outBuffer2 outBuffer.Length SocketFlags.None);
                while (true)
                { 

                    int len = s.Receive(inBuffer 1024 SocketFlags.None);//如果接收的消息为空 阻塞 当前循环 
                    uint data0 = BitConverter.ToUInt32(inBuffer 0);
                    uint data1 = BitConverter.ToUInt32(inBuffer 4);
                    uint data2 = BitConverter.ToUInt32(inBuffer 8);
                    uint data3 = BitConverter.ToUInt32(inBuffer 12);
                    List listnewbyte = new List();
                    //16位Hash
                    for (var ivalueid = 0; ivalueid < 16; ivalueid++) {
                        listnewbyte.Add(inBuffer[ivalueid+16]);
                    }
                    var data4= Encoding.ASCII.GetString(listnewbyte.ToArray());
                    uint data5 = BitConverter.ToUInt32(inBuffer 33);
                    Console.WriteLine(data0);
                    Console.WriteLine(data1);
                    Console.WriteLine(data2);
                    Console.WriteLine(data3);
                    Console.WriteLine(data4);
                    Console.WriteLine(data5);

                   var data = s.Send(inBuffer outBuffer.Length SocketFlags.None);
                    if (len == 0) {
                        break;
                    }

                    uint idata= (char)inBuffer[0];
                    
              

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

    ..A..H.     44544  2020-08-18 08:16  Socket\.vs\Socket\v14\.suo

    ..A..H.     53248  2020-08-18 10:54  Socket\.vs\Socket\v16\.suo

     文件        189  2020-08-17 10:06  Socket\Socket\App.config

     文件       6144  2020-08-18 10:54  Socket\Socket\bin\Debug\Socket.exe

     文件        189  2020-08-17 10:06  Socket\Socket\bin\Debug\Socket.exe.config

     文件      15872  2020-08-18 10:54  Socket\Socket\bin\Debug\Socket.pdb

     文件      22696  2020-08-18 08:16  Socket\Socket\bin\Debug\Socket.vshost.exe

     文件        189  2020-08-17 10:06  Socket\Socket\bin\Debug\Socket.vshost.exe.config

     文件        490  2019-03-19 12:46  Socket\Socket\bin\Debug\Socket.vshost.exe.manifest

     文件        214  2020-08-17 17:38  Socket\Socket\obj\Debug\.NETframeworkVersion=v4.5.2.AssemblyAttributes.cs

     文件       6788  2020-08-17 17:39  Socket\Socket\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件         42  2020-08-18 08:19  Socket\Socket\obj\Debug\Socket.csproj.CoreCompileInputs.cache

     文件       1295  2020-08-18 08:19  Socket\Socket\obj\Debug\Socket.csproj.FileListAbsolute.txt

     文件        424  2020-08-18 09:50  Socket\Socket\obj\Debug\Socket.csprojAssemblyReference.cache

     文件       1922  2020-08-17 11:15  Socket\Socket\obj\Debug\Socket.csprojResolveAssemblyReference.cache

     文件       6144  2020-08-18 10:54  Socket\Socket\obj\Debug\Socket.exe

     文件      15872  2020-08-18 10:54  Socket\Socket\obj\Debug\Socket.pdb

     文件          0  2020-08-17 10:06  Socket\Socket\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2020-08-17 10:06  Socket\Socket\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2020-08-17 10:06  Socket\Socket\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       3243  2020-08-18 11:00  Socket\Socket\Program.cs

     文件       1320  2020-08-17 10:06  Socket\Socket\Properties\AssemblyInfo.cs

     文件       2672  2020-08-17 10:06  Socket\Socket\Socket.csproj

     文件        985  2020-08-17 10:06  Socket\Socket.sln

     目录          0  2020-08-17 10:06  Socket\Socket\obj\Debug\TempPE

     目录          0  2020-08-18 08:17  Socket\.vs\Socket\v14

     目录          0  2020-08-18 08:17  Socket\.vs\Socket\v16

     目录          0  2020-08-18 08:17  Socket\Socket\bin\Debug

     目录          0  2020-08-18 09:50  Socket\Socket\obj\Debug

     目录          0  2020-08-18 08:17  Socket\.vs\Socket

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

评论

共有 条评论