资源简介
含服务端以及客户端,支持发送图片和文字
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using TCPLibrary;
using TCPLibrary.Abstracts;
using TCPLibrary.DefaultImplements;
namespace TCPClient
{
public partial class Form1 : Form
{
baseClientSocket _client;
baseProxySocket _proxy;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender EventArgs e)
{
_client = new baseClientSocket();
_client.Connected += new ConnectedEventHandler(_client_Connected);
_client.DisConnected += new DisConnectedEventHandler(_client_DisConnected);
_client.MessageReceived += new MessageReceivedEventHandler(_client_MessageReceived);
_client.Connect(“127.0.0.1“9100);
}
void _client_MessageReceived(ZProxySocket proxySocket ZMessage message)
{
this.Invoke((Action)(delegate()
{
baseMessage msg = message as baseMessage;
if (msg.MsgType == 1) //文本
{
textBox1.AppendText(proxySocket.RemoteIP + “:“ + proxySocket.RemotePort + “ 发送一条文本消息:\r\n“);
textBox1.AppendText(Encoding.Unicode.GetString(msg.MsgContent) + “\r\n“);
}
if (msg.MsgType == 2) //图片
{
textBox1.AppendText(proxySocket.RemoteIP + “:“ + proxySocket.RemotePort + “ 发送一条图片消息:\r\n“);
BinaryFormatter bf = new BinaryFormatter();
pictureBox1.Image = bf.Deserialize(new MemoryStream(msg.MsgContent)) as Bitmap; //将内容反序列化为bitmap
}
}));
}
void _client_DisConnected(ZProxySocket proxySocket)
{
this.Invoke((Action)(delegate()
{
textBox1.AppendText(“与服务器断开\r\n“);
}));
}
void _client_Connected(ZProxySocket proxySocket)
{
this.Invoke((Action)(delegate()
{
if (proxySocket == null)
{
textBox1.AppendText(“连接服务器失败!“);
}
else
{
textBox1.AppendText(“连接服务器 “ + proxySocket.RemoteIP + “:“ + proxySocket.RemotePort + “ 成功!“);
_proxy = proxySocket as baseProxySocket;
}
}));
}
private void button1_Click(object sender EventArgs e)
{
_proxy.SendMessage(new baseMessage(1 Encoding.Unicode.GetBytes(textBox2.Text))); //发送baseMessage消息
}
private void button2_Click(object sender EventArgs e)
{
using
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 185344 2020-05-02 21:12 TCPDemo\TCPDemo\.vs\TCPDemo\v16\.suo
文件 12288 2020-05-08 14:02 TCPDemo\TCPDemo\TCPClient\bin\Debug\TCPClient.exe
文件 32256 2020-05-08 14:02 TCPDemo\TCPDemo\TCPClient\bin\Debug\TCPClient.pdb
文件 23168 2020-05-08 14:03 TCPDemo\TCPDemo\TCPClient\bin\Debug\TCPClient.vshost.exe
文件 490 2019-03-19 12:46 TCPDemo\TCPDemo\TCPClient\bin\Debug\TCPClient.vshost.exe.manifest
文件 11776 2020-05-02 21:05 TCPDemo\TCPDemo\TCPClient\bin\Debug\TCPLibrary.dll
文件 38400 2020-05-02 21:05 TCPDemo\TCPDemo\TCPClient\bin\Debug\TCPLibrary.pdb
文件 3724 2015-01-23 13:50 TCPDemo\TCPDemo\TCPClient\Form1.cs
文件 5076 2015-01-23 13:50 TCPDemo\TCPDemo\TCPClient\Form1.Designer.cs
文件 5817 2015-01-23 13:50 TCPDemo\TCPDemo\TCPClient\Form1.resx
文件 2873 2020-05-08 14:01 TCPDemo\TCPDemo\TCPClient\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 7213 2020-05-08 14:01 TCPDemo\TCPDemo\TCPClient\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 1908 2020-05-08 14:03 TCPDemo\TCPDemo\TCPClient\obj\x86\Debug\TCPClient.csproj.FileListAbsolute.txt
文件 904 2020-05-08 14:02 TCPDemo\TCPDemo\TCPClient\obj\x86\Debug\TCPClient.csproj.GenerateResource.Cache
文件 34256 2020-05-02 21:03 TCPDemo\TCPDemo\TCPClient\obj\x86\Debug\TCPClient.csprojAssemblyReference.cache
文件 11608 2020-05-08 14:02 TCPDemo\TCPDemo\TCPClient\obj\x86\Debug\TCPClient.csprojResolveAssemblyReference.cache
文件 12288 2020-05-08 14:02 TCPDemo\TCPDemo\TCPClient\obj\x86\Debug\TCPClient.exe
文件 180 2020-05-08 14:02 TCPDemo\TCPDemo\TCPClient\obj\x86\Debug\TCPClient.Form1.resources
文件 32256 2020-05-08 14:02 TCPDemo\TCPDemo\TCPClient\obj\x86\Debug\TCPClient.pdb
文件 180 2020-05-08 14:02 TCPDemo\TCPDemo\TCPClient\obj\x86\Debug\TCPClient.Properties.Resources.resources
文件 501 2015-01-23 09:14 TCPDemo\TCPDemo\TCPClient\Program.cs
文件 1430 2015-01-23 09:14 TCPDemo\TCPDemo\TCPClient\Properties\AssemblyInfo.cs
文件 2848 2015-01-23 09:14 TCPDemo\TCPDemo\TCPClient\Properties\Resources.Designer.cs
文件 5612 2015-01-23 09:14 TCPDemo\TCPDemo\TCPClient\Properties\Resources.resx
文件 1096 2015-01-23 09:14 TCPDemo\TCPDemo\TCPClient\Properties\Settings.Designer.cs
文件 249 2015-01-23 09:14 TCPDemo\TCPDemo\TCPClient\Properties\Settings.settings
文件 3895 2015-01-23 13:22 TCPDemo\TCPDemo\TCPClient\TCPClient.csproj
文件 3514 2015-01-23 10:41 TCPDemo\TCPDemo\TCPDemo.sln
..A..H. 79360 2015-01-23 13:52 TCPDemo\TCPDemo\TCPDemo.suo
..A..H. 158720 2020-05-08 14:03 TCPDemo\TCPDemo\TCPDemo.v12.suo
............此处省略81个文件信息
- 上一篇:C#实现串口上位机
- 下一篇:C#唤起微信刷脸支付摄像头
评论
共有 条评论