用VB5 Winsock控件創(chuàng)建TCP/IP通訊程序 隨著Windows 95中文版和Windows NT Server 4.0中文版的流行, Microsoft公司推出了相應(yīng)平臺(tái)上的開(kāi)發(fā)軟件: Visual Basic 5.0 中文企業(yè) 版。它為Windows環(huán)境下的網(wǎng)絡(luò)開(kāi)發(fā)提供了強(qiáng)大的工具,Winsock控件就是其中之一。 Winsock控件建立在TCP、UDP協(xié)議的基礎(chǔ)上,完成與遠(yuǎn)程計(jì)算機(jī)的通信。即使對(duì)TCP/IP不太熟悉的用戶(hù),使用該控件也可以在十幾分鐘內(nèi)創(chuàng)建一個(gè)簡(jiǎn)單的客戶(hù)機(jī)/服務(wù)器程序。下面我們對(duì)Winsock控件的事件、方法、屬性按其在程序中出現(xiàn)的順序分別作詳細(xì)的介紹,以便更好地理解程序源代碼。
成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括廣靈網(wǎng)站建設(shè)、廣靈網(wǎng)站制作、廣靈網(wǎng)頁(yè)制作以及廣靈網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃等。多年來(lái),我們專(zhuān)注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,廣靈網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶(hù)以成都為中心已經(jīng)輻射到廣靈省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶(hù)的支持與信任!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Diagnostics;
namespace QQLogin
{
public partial class QQLoginForm : Form
{
public QQLoginForm()
{
InitializeComponent();
}
UserInfo ui;
private void button1_Click(object sender, EventArgs e)
{
//單用戶(hù)登陸
if (ui == null)
{
ui = new UserInfo();//如果沒(méi)有提取出來(lái)對(duì)象,就創(chuàng)建一個(gè)
}
if (ui != null)
{
ui.Username = this.txtUser.Text.Trim();
ui.Password = this.txtPwd.Text;
ui.Type = this.cboType.Text == "正常" ? "41" : "40";
if (this.ValidateInput())
{//驗(yàn)證是否輸入完全
if (string.IsNullOrEmpty(ui.Path))
{//判斷是否有QQ路徑,如果沒(méi)有就打開(kāi)對(duì)話(huà)框來(lái)選擇一下
DialogResult dr = this.opfQQ.ShowDialog();
if (dr == DialogResult.OK)
{
ui.Path = opfQQ.FileName;//將選擇的路徑賦值給對(duì)象
this.LoginQQ(ui.Username, ui.Password, ui.Type, ui.Path);//登陸QQ
}
}
else
{
this.LoginQQ(ui.Username, ui.Password, ui.Type, ui.Path);
}
}
SerializeHelper.SerializeUserInfo(ui);//每次登陸都序列化保存一次
}
}
private bool ValidateInput()
{//驗(yàn)證是否輸入完整
if (this.txtUser.Text == "")
{
this.txtUser.Focus();
return false;
}
else if(this.txtPwd.Text=="")
{
this.txtPwd.Focus();
return false;
}
return true;
}
private void LoginQQ(string user,string pwd,string type,string path)
{//登陸QQ的命令,通過(guò)CMD命令來(lái)執(zhí)行
Process MyProcess = new Process();
//設(shè)定程序名
MyProcess.StartInfo.FileName = "cmd.exe";
//關(guān)閉Shell的使用
MyProcess.StartInfo.UseShellExecute = false;
//重定向標(biāo)準(zhǔn)輸入
MyProcess.StartInfo.RedirectStandardInput = true;
//重定向標(biāo)準(zhǔn)輸出
MyProcess.StartInfo.RedirectStandardOutput = true;
//重定向錯(cuò)誤輸出
MyProcess.StartInfo.RedirectStandardError = true;
//設(shè)置不顯示窗口
MyProcess.StartInfo.CreateNoWindow = true;
//執(zhí)行強(qiáng)制結(jié)束命令
MyProcess.Start();
MyProcess.StandardInput.WriteLine(path+" /start QQUIN:"+user+" PWDHASH:" + EncodeHash.pwdHash(pwd) + " /stat:"+type);//直接結(jié)束進(jìn)程ID
MyProcess.StandardInput.WriteLine("Exit");
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void txtUser_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar '0' || e.KeyChar '9')e.KeyChar!=8)
{//只能輸入數(shù)字和退格鍵
e.Handled = true;
}
}
private void QQLoginForm_Load(object sender, EventArgs e)
{
LoadInfo();//單用戶(hù)獲取
}
private void LoadInfo()
{//單用戶(hù)獲取
ui = SerializeHelper.DeserializeUserInfo();//返回獲取后對(duì)象
if (ui != null)
{
this.txtUser.Text = ui.Username;//填充文本框
this.txtPwd.Text = ui.Password;//填充密碼框
this.cboType.SelectedIndex = ui.Type == "41" ? 0 : 1;//選擇登陸方式
}
else
{
this.cboType.SelectedIndex = 0;
}
}
private void btnConfig_Click(object sender, EventArgs e)
{
ConfigForm cf = new ConfigForm();
cf.ShowDialog();
LoadInfo();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace QQLogin
{
public partial class ConfigForm : Form
{
UserInfo ui;
public ConfigForm()
{
InitializeComponent();
}
private void txtPath_Click(object sender, EventArgs e)
{//點(diǎn)擊一次文本框,彈出一次對(duì)話(huà)框來(lái)選擇QQ路徑
DialogResult dr = this.opfQQ.ShowDialog();
if (dr == DialogResult.OK)
{
this.txtPath.Text = opfQQ.FileName;
}
}
private bool ValidateInput()
{//驗(yàn)證是否輸入完整
if (this.txtUser.Text == "")
{
this.txtUser.Focus();
return false;
}
else if (this.txtPwd.Text == "")
{
this.txtPwd.Focus();
return false;
}
else if (this.txtPath.Text == "")
{
return false;
}
return true;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void ConfigForm_Load(object sender, EventArgs e)
{
LoadInfo();
}
private void btnSave_Click(object sender, EventArgs e)
{
ui = new UserInfo();
ui.Username = this.txtUser.Text.Trim();
ui.Password = this.txtPwd.Text;
ui.Type = this.cboType.Text == "正常" ? "41" : "40";
ui.Path = this.txtPath.Text;
if (this.ValidateInput())
{
SerializeHelper.SerializeUserInfo(ui);
this.Close();
}
}
private void LoadInfo()
{
ui = SerializeHelper.DeserializeUserInfo();
if (ui != null)
{
this.txtUser.Text = ui.Username;
this.txtPwd.Text = ui.Password;
this.cboType.SelectedIndex = ui.Type == "41" ? 0 : 1;
this.txtPath.Text = ui.Path;
}
else
{
this.cboType.SelectedIndex = 0;
}
}
}
}
你不用程序的情況能不能用TAB切換焦點(diǎn)。如果這樣不行的話(huà)你用程序控件是沒(méi)用的。
或都直接對(duì)第二個(gè)編輯框發(fā)送消息。
常見(jiàn)兩種方式:
使用短信網(wǎng)關(guān),有第三方的,也有和移動(dòng)電信等簽約的。后者一般是大客戶(hù)才開(kāi)放。前者你百度搜“短信通”就可以找到很多家提供這種服務(wù)的公司。提供的接口一般是http協(xié)議的調(diào)用。在C# WINFORM里就可以使用WebClient類(lèi)來(lái)調(diào)用了。具體的接口你還是得看不同公司提供的文檔。
使用短信貓。是一個(gè)硬件設(shè)備,可以插SIM卡,然后通過(guò)短信貓?zhí)峁┑腁PI去調(diào)用…具體還是得看那個(gè)API…我用過(guò)一個(gè)是提供一個(gè)dll給你import的。其他應(yīng)該也一樣
Visual C#實(shí)現(xiàn)短信息發(fā)送的具體實(shí)現(xiàn)步驟:
Visual C#發(fā)送短信息的關(guān)鍵就是通過(guò)Web引用新浪網(wǎng)提供的發(fā)送短信息的Web Service,并在引用完成后。調(diào)用此Service的sendXml方法即可。以下就是Visual C#引用Web Service發(fā)送短信息的具體實(shí)現(xiàn)步驟:
1. 啟動(dòng)Visual Studio .Net。
2. 選擇菜單【文件】|【新建】|【項(xiàng)目】后,彈出【新建項(xiàng)目】對(duì)話(huà)框。
3. 將【項(xiàng)目類(lèi)型】設(shè)置為【Visual Basic項(xiàng)目】。
4. 將【模板】設(shè)置為【W(wǎng)indows應(yīng)用程序】。
5. 在【名稱(chēng)】文本框中輸入【短信】。
6. 在【位置】的文本框中輸入【E:/VS.NET項(xiàng)目】,然后單擊【確定】按鈕,這樣在"E:/VS.NET項(xiàng)目"目錄中就產(chǎn)生了名稱(chēng)為"短信"的文件夾,并在里面創(chuàng)建了名稱(chēng)為"短信"的項(xiàng)目文件。
7. 把Visual Studio .Net的當(dāng)前窗口切換到【Form1.cs(設(shè)計(jì))】窗口,并從【工具箱】中的【W(wǎng)indows窗體組件】選項(xiàng)卡中往Form1窗體中拖入下列組件,并執(zhí)行相應(yīng)的操作:
四個(gè)Label組件。
四個(gè)TextBox組件。
一個(gè)Button組件,其作用是發(fā)送短信息。并在這個(gè)Button組件拖入Form1的設(shè)計(jì)窗體后,雙擊它,則系統(tǒng)會(huì)在Form1.cs文件分別產(chǎn)生這個(gè)組件的Click事件對(duì)應(yīng)的處理代碼。
8. 把Visual Studio .Net的當(dāng)前窗口切換到Form1.vb的代碼編輯窗口,并用下列代碼替換Form1.cs中的InitializeComponent過(guò)程對(duì)應(yīng)的代碼,下列代碼作用是初始化窗體中加入的組件:
private void InitializeComponent ( )
{
this.textBox1 = new System.Windows.Forms.TextBox ( ) ;
this.textBox2 = new System.Windows.Forms.TextBox ( ) ;
this.textBox3 = new System.Windows.Forms.TextBox ( ) ;
this.button1 = new System.Windows.Forms.Button ( ) ;
this.label1 = new System.Windows.Forms.Label ( ) ;
this.label2 = new System.Windows.Forms.Label ( ) ;
this.label3 = new System.Windows.Forms.Label ( ) ;
this.label4 = new System.Windows.Forms.Label ( ) ;
this.textBox4 = new System.Windows.Forms.TextBox ( ) ;
this.SuspendLayout ( ) ;
this.textBox1.Location = new System.Drawing.Point ( 144 , 16 ) ;
this.textBox1.Name = "textBox1" ;
this.textBox1.Size = new System.Drawing.Size ( 184 , 21 ) ;
this.textBox1.TabIndex = 0 ;
this.textBox1.Text = "" ;
this.textBox2.Location = new System.Drawing.Point ( 144 , 69 ) ;
this.textBox2.Name = "textBox2" ;
this.textBox2.PasswordChar = ''''''''*'''''''' ;
this.textBox2.Size = new System.Drawing.Size ( 184 , 21 ) ;
this.textBox2.TabIndex = 1 ;
this.textBox2.Text = "" ;
this.textBox3.Location = new System.Drawing.Point ( 144 , 122 ) ;
this.textBox3.Name = "textBox3" ;
this.textBox3.Size = new System.Drawing.Size ( 184 , 21 ) ;
this.textBox3.TabIndex = 2 ;
this.textBox3.Text = "" ;
this.button1.Location = new System.Drawing.Point ( 152 , 256 ) ;
this.button1.Name = "button1" ;
this.button1.Size = new System.Drawing.Size ( 80 , 32 ) ;
this.button1.TabIndex = 4 ;
this.button1.Text = "發(fā)送" ;
this.button1.Click += new System.EventHandler ( this.button1_Click ) ;
this.label1.Location = new System.Drawing.Point ( 56 , 24 ) ;
this.label1.Name = "label1" ;
this.label1.Size = new System.Drawing.Size ( 88 , 16 ) ;
this.label1.TabIndex = 5 ;
this.label1.Text = "注冊(cè)手機(jī)號(hào):" ;
this.label2.Location = new System.Drawing.Point ( 88 , 77 ) ;
this.label2.Name = "label2" ;
this.label2.Size = new System.Drawing.Size ( 72 , 16 ) ;
this.label2.TabIndex = 6 ;
this.label2.Text = "口令:" ;
this.label3.Location = new System.Drawing.Point ( 56 , 128 ) ;
this.label3.Name = "label3" ;
this.label3.Size = new System.Drawing.Size ( 96 , 16 ) ;
this.label3.TabIndex = 7 ;
this.label3.Text = "目標(biāo)手機(jī)號(hào):" ;
this.label4.Location = new System.Drawing.Point ( 96 , 176 ) ;
this.label4.Name = "label4" ;
this.label4.Size = new System.Drawing.Size ( 72 , 16 ) ;
this.label4.TabIndex = 8 ;
this.label4.Text = "內(nèi)容:" ;
this.textBox4.Location = new System.Drawing.Point ( 144 , 175 ) ;
this.textBox4.Multiline = true ;
this.textBox4.Name = "textBox4" ;
this.textBox4.Size = new System.Drawing.Size ( 184 , 48 ) ;
this.textBox4.TabIndex = 3 ;
this.textBox4.Text = "" ;
this.AutoScaleBaseSize = new System.Drawing.Size ( 6 , 14 ) ;
this.ClientSize = new System.Drawing.Size ( 410 , 303 ) ;
this.Controls.Add ( this.button1 ) ;
this.Controls.Add ( this.textBox4 ) ;
this.Controls.Add ( this.textBox3 ) ;
this.Controls.Add ( this.textBox2 ) ;
this.Controls.Add ( this.textBox1 ) ;
this.Controls.Add ( this.label4 ) ;
this.Controls.Add ( this.label3 ) ;
this.Controls.Add ( this.label2 ) ;
this.Controls.Add ( this.label1 ) ;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle ;
this.MaximizeBox = false ;
this.Name = "Form1" ;
this.Text = "Visual C#實(shí)現(xiàn)短信發(fā)送" ;
this.ResumeLayout ( false ) ;
}
當(dāng)前名稱(chēng):短信發(fā)送代碼vb.net 接收短信代碼
轉(zhuǎn)載注明:http://jinyejixie.com/article12/ddoigdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、服務(wù)器托管、企業(yè)建站、外貿(mào)建站、域名注冊(cè)、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)