91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5.86MB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-09-22
  • 語言: 其他
  • 標(biāo)簽: supersocket??套接字??

資源簡介

使用一個(gè)開源的套接字通信框架(supersocket)來實(shí)現(xiàn)的模擬路燈通信的控制系統(tǒng)。 有興趣研究套接字和supersocket相關(guān)技術(shù)的人士可以下載下來參考一下。

資源截圖

代碼片段和文件信息

/*
?*?由SharpDevelop創(chuàng)建。
?*?用戶:?cjt
?*?日期:?2013-8-4
?*?時(shí)間:?7:46
?*?
?*?要改變這種模板請(qǐng)點(diǎn)擊?工具|選項(xiàng)|代碼編寫|編輯標(biāo)準(zhǔn)頭文件
?*/
using?System;
using?System.Collections.Generic;
using?System.Drawing;
using?System.IO;
using?System.Net;
using?System.Net.Sockets;
using?System.Text;
using?System.Threading;
using?System.Windows.Forms;

using?UserControlLight;

namespace?StreetLightClient
{
///?
///?模擬路燈
///?

public?partial?class?MainForm?:?Form
{
private?Socket?socket;
public?delegate?void?InvokeTxtDelegate(string?txt);
public?MainForm()
{
InitializeComponent();

try
{
//連接服務(wù)器
EndPoint?serverAddress?=?new?IPEndPoint(IPAddress.Parse(“127.0.0.1“)?2013);
socket?=?new?Socket(serverAddress.AddressFamily?SocketType.Stream?ProtocolType.Tcp);
socket.Connect(serverAddress);

Thread?listenThread=new?Thread(new?ThreadStart(ListenFromServer));
listenThread.Start();
}
catch?(Exception)
{
MessageBox.Show(“無法連接主機(jī)!“);
Environment.Exit(1);
}
}

//用于偵聽從服務(wù)器發(fā)過來的消息
private?void?ListenFromServer()
{
byte[]?info=new?byte[256];
socket.Receive(info);

AsyncCallback?callBack?=?new?AsyncCallback(ListenCallBack);
socket.BeginReceive(info0?256?SocketFlags.NonecallBackinfo);
}

//異步接收到服務(wù)器發(fā)過來的消息后的回調(diào)方法
private?void?ListenCallBack(IAsyncResult?result)
{
byte[]?info=(byte[])result.AsyncState;
string?message?=?Encoding.ASCII.GetString(info);
string[]?messages=message.Split(‘?‘);
switch?(messages[0])
{
case?“SETNAME“:
messages[1].Replace(“$“““);
SetName(messages[1]);
break;
default:
break;
}
}

private?void?Timer1Tick(object?sender?EventArgs?e)
{
if(lightControl.LightState?==?EnumLightState.On)
{
if(lightControl.LightPower>0)
{
//路燈處于打開狀態(tài),電量不斷減少
lightControl.LightPower--;

//向服務(wù)器端發(fā)送消息
byte[]?info?=?Encoding.ASCII.GetBytes(“SETPOWER?“+lightControl.LightPower+“$“);
socket.Send(info);
}
else
{
lightControl.LightState=?EnumLightState.Off;

//向服務(wù)器端發(fā)送消息
byte[]?info?=?Encoding.ASCII.GetBytes(“SETLIGHTSTATE?OFF$“);
socket.Send(info);
}
}
else?if(lightControl.LightState??==?EnumLightState.Charging)
{
if(lightControl.LightPower<10)
{
//路燈處于充電狀態(tài),電量不斷增加
lightControl.LightPower++;

//向服務(wù)器端發(fā)送消息
byte[]?info?=?Encoding.ASCII.GetBytes(“SETPOWER?“+lightControl.LightPower+“$“);
socket.Send(info);
}
}
}

//程序退出時(shí)斷開連接
private?void?MainFormFormClosing(object?sender?FormClosingEventArgs?e)
{
socket.Disconnect(false);
}

//燈亮事件
private ?void?LightControlLightOnEvent()
{
byte[]?info?=?Encoding.ASCII.GetBytes(“SETLIGHTSTATE?ON$“);
socket.Send(info);
}

//燈滅事件
private void?LightControlLightOffEvent()
{
byte[]?info?=?Encoding.ASCII.GetBytes(“SETLIGH

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-08-05?23:52??StreetLight\
?????目錄???????????0??2013-08-05?23:54??StreetLight\bin\
?????文件??????286720??2013-07-29?22:00??StreetLight\bin\log4net.dll
?????文件???????36864??2013-08-05?23:54??StreetLight\bin\StreetLightClient.exe
?????文件?????????173??2013-08-04?07:46??StreetLight\bin\StreetLightClient.exe.config
?????文件???????24064??2013-08-05?23:54??StreetLight\bin\StreetLightClient.pdb
?????文件???????24576??2013-08-05?23:54??StreetLight\bin\StreetLightControl.exe
?????文件?????????726??2013-08-05?21:10??StreetLight\bin\StreetLightControl.exe.config
?????文件???????26112??2013-08-05?23:54??StreetLight\bin\StreetLightControl.pdb
?????文件???????30720??2013-08-03?08:46??StreetLight\bin\SuperSocket.Common.dll
?????文件???????91648??2013-08-03?08:46??StreetLight\bin\SuperSocket.Common.pdb
?????文件???????57322??2013-08-03?08:46??StreetLight\bin\SuperSocket.Common.xml
?????文件???????17920??2013-08-03?08:46??StreetLight\bin\SuperSocket.Facility.dll
?????文件???????50688??2013-08-03?08:46??StreetLight\bin\SuperSocket.Facility.pdb
?????文件???????30037??2013-08-03?08:46??StreetLight\bin\SuperSocket.Facility.xml
?????文件??????100864??2013-08-03?08:46??StreetLight\bin\SuperSocket.Socketbase.dll
?????文件??????208384??2013-08-03?08:46??StreetLight\bin\SuperSocket.Socketbase.pdb
?????文件??????231933??2013-08-03?08:46??StreetLight\bin\SuperSocket.Socketbase.xml
?????文件???????86528??2013-08-03?08:46??StreetLight\bin\SuperSocket.SocketEngine.dll
?????文件??????208384??2013-08-03?08:46??StreetLight\bin\SuperSocket.SocketEngine.pdb
?????文件???????51038??2013-08-03?08:46??StreetLight\bin\SuperSocket.SocketEngine.xml
?????文件???????26112??2013-08-05?23:54??StreetLight\bin\UserControlLight.dll
?????文件???????22016??2013-08-05?23:54??StreetLight\bin\UserControlLight.pdb
?????文件????????2137??2013-08-05?22:23??StreetLight\StreetLight.sln
?????目錄???????????0??2013-08-05?23:50??StreetLight\StreetLightClient\
?????文件?????????173??2013-08-04?07:46??StreetLight\StreetLightClient\app.config
?????目錄???????????0??2013-08-04?22:34??StreetLight\StreetLightClient\bin\
?????文件????????3763??2013-08-05?23:50??StreetLight\StreetLightClient\LightClientForm.cs
?????文件????????2858??2013-08-05?21:13??StreetLight\StreetLightClient\LightClientForm.Designer.cs
?????文件????????6011??2013-08-05?21:13??StreetLight\StreetLightClient\LightClientForm.resx
?????目錄???????????0??2013-08-04?07:45??StreetLight\StreetLightClient\obj\
............此處省略107個(gè)文件信息

評(píng)論

共有 條評(píng)論

相關(guān)資源