• 大小: 720KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-27
  • 语言: C#
  • 标签: SOCKET,C#  

资源简介

C#socket通信调用Brother打印机(客户端和服务端)源代码, 详细注释版

资源截图

代码片段和文件信息

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WFClient
{
    public partial class Form1 : Form
    {
        /// 
        /// 用来存放连接服务的IP地址和端口号,对应的Socket (这个为了以后的扩展用,现在暂时没用)
        /// 

        Dictionary dicSocket = new Dictionary();

        /// 
        /// 负责通信的Socket
        /// 

        Socket socketSend;    

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            //不检测跨线程之间的空间调用
            Control.CheckForIllegalCrossThreadCalls = false;
        }

        /// 
        /// 建立连接
        /// 

        /// 
        /// 
        private void connectionSer_Click(object sender EventArgs e)
        {
            try
            {
                //创建负责通信的Socket
                socketSend = new Socket(AddressFamily.InterNetwork SocketType.Stream ProtocolType.Tcp);

                //获取服务端的IP
                IPAddress ip = IPAddress.Parse(sipAddress.Text.Trim());

                //获取服务端的端口号
                IPEndPoint port = new IPEndPoint(ip Convert.ToInt32(serverPort.Text.Trim()));

                //获得要连接的远程服务器应用程序的IP地址和端口号
                socketSend.Connect(port);
                
                //新建线程,去接收客户端发来的信息
                Thread td = new Thread(AcceptMgs);
                td.IsBackground = true;
                td.Start();
            }
            catch { }
        }

        /// 
        /// 发送数据
        /// 

        /// 
        /// 
        private void btnSend_Click(object sender EventArgs e)
        {
            try
            {
                PrintData tempData = new PrintData();
                tempData.TemplatePath = @“C:\templates“;
                tempData.TemplateName = “lablete.lbx“;
                
                  Dictionary printData = new Dictionary();
                     printData.Add(“objName“ sendMessage.Text);
                printData.Add(“objNum“ “Test1026-2“);
                tempData.PrintDataList = printData;

                List printDataList = new List();
                printDataList.Add(tempData);

                //实体序列化和反序列化  
                string json1 = Serializeobject(printDataList);

                byte[] buffer = Encoding.UTF8.GetBytes(json1);
                 
                //将字节数组传递给客户端
                socketSend.Send(buffer);
                sendMessa

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-10-26 09:10  WFSocket\
     目录           0  2016-10-26 14:21  WFSocket\WFClient\
     文件         187  2016-10-25 15:46  WFSocket\WFClient\App.config
     目录           0  2016-10-26 09:10  WFSocket\WFClient\bin\
     目录           0  2016-10-26 09:10  WFSocket\WFClient\bin\Debug\
     文件      526336  2016-06-13 23:05  WFSocket\WFClient\bin\Debug\Newtonsoft.Json.dll
     文件       12800  2016-10-26 17:29  WFSocket\WFClient\bin\Debug\WFClient.exe
     文件         187  2016-10-25 15:46  WFSocket\WFClient\bin\Debug\WFClient.exe.config
     文件       32256  2016-10-26 17:29  WFSocket\WFClient\bin\Debug\WFClient.pdb
     文件       24224  2016-10-27 11:20  WFSocket\WFClient\bin\Debug\WFClient.vshost.exe
     文件         187  2016-10-25 15:46  WFSocket\WFClient\bin\Debug\WFClient.vshost.exe.config
     文件         490  2012-06-06 02:06  WFSocket\WFClient\bin\Debug\WFClient.vshost.exe.manifest
     文件        4758  2016-10-26 14:13  WFSocket\WFClient\Form1.cs
     文件        7053  2016-10-25 16:08  WFSocket\WFClient\Form1.Designer.cs
     文件        5817  2016-10-25 16:08  WFSocket\WFClient\Form1.resx
     目录           0  2016-10-26 09:10  WFSocket\WFClient\obj\
     目录           0  2016-10-26 17:29  WFSocket\WFClient\obj\Debug\
     文件         865  2016-10-25 17:02  WFSocket\WFClient\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6977  2016-10-26 11:30  WFSocket\WFClient\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件           0  2016-10-25 15:46  WFSocket\WFClient\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2016-10-25 15:46  WFSocket\WFClient\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2016-10-25 15:46  WFSocket\WFClient\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2016-10-25 15:46  WFSocket\WFClient\obj\Debug\TempPE\
     文件        1207  2016-10-27 11:20  WFSocket\WFClient\obj\Debug\WFClient.csproj.FileListAbsolute.txt
     文件         977  2016-10-25 20:02  WFSocket\WFClient\obj\Debug\WFClient.csproj.GenerateResource.Cache
     文件       12209  2016-10-26 14:14  WFSocket\WFClient\obj\Debug\WFClient.csprojResolveAssemblyReference.cache
     文件       12800  2016-10-26 17:29  WFSocket\WFClient\obj\Debug\WFClient.exe
     文件         180  2016-10-25 17:26  WFSocket\WFClient\obj\Debug\WFClient.Form1.resources
     文件       32256  2016-10-26 17:29  WFSocket\WFClient\obj\Debug\WFClient.pdb
     文件         180  2016-10-25 17:26  WFSocket\WFClient\obj\Debug\WFClient.Properties.Resources.resources
     文件         409  2016-10-26 14:21  WFSocket\WFClient\PrintData.cs
............此处省略52个文件信息

评论

共有 条评论

相关资源