資源簡介
這是一個利用C#編寫的一個簡易的局域網(wǎng)聊天工具,利用了UDP的網(wǎng)絡(luò)協(xié)議!
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Net;
using?System.Net.Sockets;
using?System.Windows.Forms;
namespace?SGSclient
{
????public?partial?class?LoginForm?:?Form
????{
????????public?Socket?clientSocket;
????????public?EndPoint?epServer;
????????public?string?strName;
????????public?LoginForm()
????????{
????????????InitializeComponent();
????????}
????????private?void?btnOK_Click(object?sender?EventArgs?e)
????????{
????????????strName?=?txtName.Text;
????????????try
????????????{
????????????????//Using?UDP?sockets
????????????????clientSocket?=?new?Socket(AddressFamily.InterNetwork?
????????????????????SocketType.Dgram?ProtocolType.Udp);
????????????????//IP?address?of?the?server?machine
????????????????IPAddress?ipAddress?=?IPAddress.Parse(txtServerIP.Text);
????????????????//Server?is?listening?on?port?1000
????????????????IPEndPoint?ipEndPoint?=?new?IPEndPoint(ipAddress?1000);
????????????????epServer?=?(EndPoint)ipEndPoint;
????????????????
????????????????Data?msgToSend?=?new?Data?();
????????????????msgToSend.cmdCommand?=?Command.Login;
????????????????msgToSend.strMessage?=?null;
????????????????msgToSend.strName?=?strName;
????????????????byte[]?byteData?=?msgToSend.ToByte();
????????????????
????????????????//Login?to?the?server
????????????????clientSocket.BeginSendTo(byteData?0?byteData.Length?
????????????????????SocketFlags.None?epServer?new?AsyncCallback(OnSend)?null);
????????????}
????????????catch?(Exception?ex)
????????????{?
????????????????MessageBox.Show(ex.Message?“SGSclient“?
????????????????????MessageBoxButtons.OK?MessageBoxIcon.Error);?
????????????}?
????????}
????????private?void?OnSend(IAsyncResult?ar)
????????{
????????????try
????????????{
????????????????clientSocket.EndSend(ar);????????????????
????????????????strName?=?txtName.Text;
????????????????DialogResult?=?DialogResult.OK;
????????????????Close();
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????MessageBox.Show(ex.Message?“SGSclient“?MessageBoxButtons.OK?MessageBoxIcon.Error);
????????????}
????????}
????????private?void?btnCancel_Click(object?sender?EventArgs?e)
????????{
????????????Close();
????????}
????????private?void?LoginForm_Load(object?sender?EventArgs?e)
????????{
????????????CheckForIllegalCrossThreadCalls?=?false;
????????}
????????private?void?txtName_TextChanged(object?sender?EventArgs?e)
????????{
????????????if?(txtName.Text.Length?>?0?&&?txtServerIP.Text.Length?>?0)
????????????????btnOK.Enabled?=?true;
????????????else
????????????????btnOK.Enabled?=?false;
????????}
????????private?void?txtServerIP_TextChanged(object?sender?EventArgs?e)
????????{
????????????if?(txtName.Text.Length?>?0?&&?txtServerIP.Text.Length?>?0)
????????????????btnOK.Enabled?=?true;
????????????else
??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????922??2006-12-24?19:46??SGSclientUDP\SGSclientUDP.sln
?????文件???????3057??2006-12-29?18:46??SGSclientUDP\SGSclient\LoginForm.cs
?????文件???????5346??2006-12-21?21:36??SGSclientUDP\SGSclient\LoginForm.Designer.cs
?????文件???????5814??2006-12-21?21:36??SGSclientUDP\SGSclient\LoginForm.resx
?????文件????????933??2006-12-24?14:21??SGSclientUDP\SGSclient\Program.cs
?????文件???????9651??2006-12-29?18:49??SGSclientUDP\SGSclient\SGSClientForm.cs
?????文件???????4378??2006-12-24?20:08??SGSclientUDP\SGSclient\SGSClientForm.Designer.cs
?????文件???????5814??2006-12-24?20:08??SGSclientUDP\SGSclient\SGSClientForm.resx
?????文件???????3722??2006-12-24?19:49??SGSclientUDP\SGSclient\SGSclientUDP.csproj
?????文件???????1282??2006-11-03?12:54??SGSclientUDP\SGSclient\Properties\AssemblyInfo.cs
?????文件???????2845??2006-11-03?12:54??SGSclientUDP\SGSclient\Properties\Resources.Designer.cs
?????文件???????5612??2006-11-03?12:54??SGSclientUDP\SGSclient\Properties\Resources.resx
?????文件???????1092??2006-11-03?12:54??SGSclientUDP\SGSclient\Properties\Settings.Designer.cs
?????文件????????249??2006-11-03?12:54??SGSclientUDP\SGSclient\Properties\Settings.settings
?????文件???????5632??2005-12-08?14:51??SGSclientUDP\SGSclient\bin\Debug\SGSclient.vshost.exe
?????文件??????28672??2008-11-28?10:55??SGSclientUDP\SGSclient\bin\Debug\SGSclient.exe
?????文件??????32256??2008-11-28?10:55??SGSclientUDP\SGSclient\bin\Debug\SGSclient.pdb
?????文件????????180??2008-11-28?10:55??SGSclientUDP\SGSclient\obj\Debug\SGSclient.SGSClient.resources
?????文件????????180??2008-11-28?10:55??SGSclientUDP\SGSclient\obj\Debug\SGSclient.LoginForm.resources
?????文件????????180??2008-11-28?10:55??SGSclientUDP\SGSclient\obj\Debug\SGSclient.Properties.Resources.resources
?????文件????????912??2008-11-28?10:55??SGSclientUDP\SGSclient\obj\Debug\SGSclientUDP.csproj.GenerateResource.Cache
?????文件??????32256??2008-11-28?10:55??SGSclientUDP\SGSclient\obj\Debug\SGSclient.pdb
?????文件??????28672??2008-11-28?10:55??SGSclientUDP\SGSclient\obj\Debug\SGSclient.exe
?????文件????????330??2008-11-28?10:56??SGSclientUDP\SGSclient\obj\SGSclientUDP.csproj.FileList.txt
????..A..H.?????10240??2008-11-28?10:56??SGSclientUDP\SGSclientUDP.suo
?????文件????????919??2006-12-24?20:08??SGSserverUDP\SGSserverUDP.sln
?????文件????????481??2006-12-21?21:39??SGSserverUDP\Server\Program.cs
?????文件??????11084??2006-12-29?18:46??SGSserverUDP\Server\SGSserverForm.cs
?????文件???????2417??2006-12-24?19:54??SGSserverUDP\Server\SGSserverForm.Designer.cs
?????文件???????5814??2006-12-24?19:54??SGSserverUDP\Server\SGSserverForm.resx
............此處省略35個文件信息
評論
共有 條評論