資源簡介
C# WINFORM 與服務器通訊,格式JSON
代碼片段和文件信息
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;
using?System.Net.Sockets;
using?System.IO;
using?System.Threading;
using?System.Configuration;
using?System.xml;
using?System.Runtime.InteropServices;
using?System.Runtime.Serialization;
using?System.Runtime.Serialization.Formatters.Binary;
using?Newtonsoft.Json;
????
namespace?MC
{
??
????public?partial?class?Form1?:?Form
????{
????????private?Socket?s;?????????????????????????????????????????//定義Socket對象??????????????????
????????string?sbnamePLCrecipeLotIdCarrierIDsStartTimesCustomersOperatorsDieLFNo;
????????Thread?threadServer?=?null;
????????List?list1?list2;
????????BinaryFormatter?bf;
????????public?bool?ConnectServer()
????????{
????????????string?server?port?eqpname;
????????????server?=?ConfigurationManager.AppSettings[“SERVER“];
????????????port?=?ConfigurationManager.AppSettings[“PORT“];
????????????eqpname?=?ConfigurationManager.AppSettings[“EQPNAME“];
????????????if?(server?==?null?||?port?==?null?||?eqpname?==?null)
????????????{
????????????????server?=?OperateIniFile.ReadIniData(“SET“?“SERVER“?null?Application.StartupPath?+?“\\data.ini“);
????????????????port?=?OperateIniFile.ReadIniData(“SET“?“PORT“?null?Application.StartupPath?+?“\\data.ini“);
????????????????eqpname?=?OperateIniFile.ReadIniData(“SET“?“EQPNAME“?null?Application.StartupPath?+?“\\data.ini“);
????????????}
????????????if?(server?==?null?||?port?==?null?||?eqpname?==?null)
????????????{
????????????????MessageBox.Show(“服務器IP地址端口或設備名字未設定!!“);
????????????????Close();
????????????}
????????????
????????????sbname?=?eqpname;
????????????if?(!s.Connected)
????????????{
????????????????IPAddress?serverIP?=?IPAddress.Parse(server);???//服務器IP
????????????????try
????????????????{
????????????????????s.Connect(serverIP?int.Parse(port));????????????????????????//連接服務器,端口號用13
????????????????}
????????????????catch?(Exception?ex)
????????????????{
????????????????????MessageBox.Show(ex.Message);
????????????????}
????????????}
????????????if?(s.Connected)
????????????{
????????????????object?jsonobject?=?new?{?TestType?=?“RequestLotInfo“??EQPID?=?sbname?};
????????????????string?jsonString?=?JsonConvert.Serializeobject(jsonobject?Newtonsoft.Json.Formatting.Indented);
????????????????textBox1.Text?=?jsonString;
????????????????clientSendMsg(jsonString);
????????????????threadServer?=?new?Thread(RecMsg);
????????????????threadServer.IsBackground?=?true;
????????????????threadServer.Start();
????????????}
????????????return?true;
????????}
????????public?Form1()
????????{
????????????InitializeComponent();
?????????????????????
????????????PLCrecipe=OperateIniFile.ReadIniData(“DATA“?“recipe“?““?Application.StartupPath+@“\data.ini“);
????????????LotId?=?OperateIniFile.Rea
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????36864??2021-01-06?09:10??8038\.vs\7M9\v15\.suo
?????文件??????????0??2021-01-04?09:27??8038\.vs\7M9\v15\Server\sqlite3\db.lock
?????文件?????552960??2021-01-06?09:10??8038\.vs\7M9\v15\Server\sqlite3\storage.ide
????..A..H.?????43520??2021-02-05?18:48??8038\.vs\8038\v15\.suo
?????文件??????????0??2021-01-07?09:29??8038\.vs\8038\v15\Server\sqlite3\db.lock
?????文件????1134592??2021-02-05?15:22??8038\.vs\8038\v15\Server\sqlite3\storage.ide
?????文件??????32768??2021-02-05?18:41??8038\.vs\8038\v15\Server\sqlite3\storage.ide-shm
?????文件????4120032??2021-02-05?18:47??8038\.vs\8038\v15\Server\sqlite3\storage.ide-wal
????..A..H.?????60928??2020-09-26?12:14??8038\.vs\MC\v16\.suo
?????文件???????4445??2021-02-05?16:15??8038\8038.csproj
?????文件???????1106??2021-01-07?09:29??8038\8038.sln
?????文件?????280153??2021-01-07?11:06??8038\8038消息格式-20201230.docx
?????文件?????280098??2021-01-07?11:06??8038\8038消息格式-20210107.docx
?????文件?????285683??2021-01-11?16:49??8038\8038消息格式-20210111.docx
?????文件???????1101??2021-02-05?16:15??8038\app.config
?????文件????????158??2020-09-21?16:23??8038\bin\Debug\2020-09-21.txt
?????文件??????67584??2021-02-05?15:52??8038\bin\Debug\8038.exe
?????文件???????1101??2021-02-05?14:56??8038\bin\Debug\8038.exe.config
?????文件??????42496??2021-02-05?15:52??8038\bin\Debug\8038.pdb
?????文件????????269??2020-09-12?10:51??8038\bin\Debug\app.config
?????文件????????546??2020-09-21?16:26??8038\bin\Debug\data.ini
?????文件?????174592??2020-09-08?10:10??8038\bin\Debug\Interop.MSxm
?????文件??????37888??2020-09-24?09:53??8038\bin\Debug\MC.exe
?????文件????????269??2020-09-13?16:22??8038\bin\Debug\MC.exe.config
?????文件?????504320??2016-01-28?14:22??8038\bin\Debug\Newtonsoft.Json.dll
?????文件??????49152??2020-09-15?15:39??8038\bin\Debug\Pc2PLC.exe
?????文件????????404??2012-09-07?14:35??8038\bin\Debug\set.ini
?????文件????????277??2020-09-21?19:40??8038\bin\Release\2020-09-21.txt
?????文件?????????82??2020-09-25?17:54??8038\bin\Release\2d.txt
?????文件??????65536??2021-02-05?18:47??8038\bin\Release\8038.exe
............此處省略98個文件信息
- 上一篇:opc ua客戶端171716
- 下一篇:C#打印條碼源碼
評論
共有 條評論