0% found this document useful (0 votes)
189 views

VB6 Network Programming (Farsi) PDF

This document provides an overview of TCP/IP and networking concepts in Visual Basic such as: - TCP/IP is a set of protocols that enable communication over the internet and includes 4 layers: application, transport, internet, and link layer. - Common application layer protocols include HTTP, FTP, SMTP, and POP. - Sockets are an abstraction layer in the transport layer used to establish TCP/IP connections and programs can perform operations like initiating connections and sending/receiving data using sockets.

Uploaded by

jet_media
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views

VB6 Network Programming (Farsi) PDF

This document provides an overview of TCP/IP and networking concepts in Visual Basic such as: - TCP/IP is a set of protocols that enable communication over the internet and includes 4 layers: application, transport, internet, and link layer. - Common application layer protocols include HTTP, FTP, SMTP, and POP. - Sockets are an abstraction layer in the transport layer used to establish TCP/IP connections and programs can perform operations like initiating connections and sending/receiving data using sockets.

Uploaded by

jet_media
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

VB

TCP/IP
: . TCP/IP
.
: Protocol
: TCP/IP
. :
- : Application Layer Pop Smtp Ftp Http Telnet
.
- : Transport Layer TCP UDP . TCP
) TCP/IP
( UDP . TCP

.
- : Layer Internet IP .
- : Link Layer
.
Socket : Port TCP/IP
. TCP UDP
. :
- : initiate accpet

- :
- : IP
: HTTP .
: FTP .
SMTP : POP email .

Web Browser

Internet Explorer iexplore.exe


load Html
. iexplore.exe ) Webbrowser
( shdocrw.dll . dll
. Mshtml.dll
html . webbrowser
. .
: Webbrowser
Webbrowser height width :
: Busy 1 load True . Stop
.
: Container 2 webbrowser
: Document 3 html . html
Document .
: LocationName 4 load webbrowser .
html .
: LocationURL 5 url load webbrowser .
: Offline 6 webbrowser True False .
: Parent 7 webbrowser .
: ReadyState 8 webbrowser .
: webbrowser :
: GoBack -1 url .
: GoForward 2 url .
: GoHome 3 homepage .
: Navigate 4 url . :
Flags,][TargetFrameName,][PostData,][Headers]x] Navigate URL
URL Flags . .
cache temperory
. Flags :
: NavOpenInNewWindow . : NavNoHistory . : NavNoReadFromCache cache . : NavNoWriteToCache cache Event : webbrowser event :
: CommandStateChange 1 Forward Back .
event :

(Command As Long, ByVal Enable As Boolean Private Sub WebBrowser1_CommandStateChange(ByVal


command 1 : 3
GoForward GoBack .
Enable .
: DocumentComplete 2 event load
ReadyState_Complete . event :
(Variant Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As
pDisp webbrowser event URL load
.
: DownloadBegin 3 event .
event .
: DownloadComplete 4 event .
: ProgressChange 5 load event .
:
(Progress As Long, ByVal ProgressMax As Long Private Sub WebBrowser1_ProgressChange(ByVal
Progress ) load ( . ProgressMax
load :
)=Progress/ProgressMax)*100 load
:
project components Microsoft Internet Controls toolbar
. WebBrowser . textbox
. event :
WebBrowser.Navigate textbox.text

- Internet Transfer

: Internet Transfer WebBrowser


. HTTP FTP .
HTTP WebBrowser
Html . FTP
.
: HTTP HTTP . Html

server client HTTP .


: OpenURL IT OpenURL . :
Inet.OpenURL(url,DataType)x
url DataType ) icString ( ) icByteArray
( . .
.
icByteArray .
: 1 Component Project Microsoft Internet Transfer Control 6.0 toolbar
. IT Rich Textbox
event :
TextBox.text=Inet.OpenURL(www.microsoft.com,icString)x
: 2 :
byte Dim b() as
B()=Inet.OpenURL(ftp://ftp.microsoft.com/test.zip,icByteArray)x
test.zip For Access Write As #1\ & App.path Open
Put #1,b()x
1# Close
: StateChanged IT event StateChanged . event
State State . . event :
Inet_StateChanged(ByVal NewState As Integer)x
NewState . :
: icNone .
: icResolvingHost IP .
: icHostResolved IP .
: icConnecting
: icConnected .
: icRequesting
: icRequestSent .
: icReceivingResponse .
: icResponseReceived .
: icDisconnecting .
: icDisconnected .
: icError .
: icResponseCompleted .
StateChanged icError
ResponseCode ResponseInfo .
: IT
. Event Driven Model
. IT

.
IT .
: GetChunk IT :
Inet.GetChunk(datasize[,datatype])x
datasize long datatype
icString icByteArray .
StateChanged icResponseReceived icResponseCompleted GetChunk
. :
Integer)x Private Sub Inet_StateChanged(Byval State as
Dim temp1,temp2
Select Case State
icResponseCompleted Case
temp1=x
temp2=x
Do
temp1=Inet.GetChunk(512,icString)x
temp1 & temp2=temp2
Loop Until temp1=x
End Select
End Sub
) 512 1024 ( .
: Execute IT Execute . :
Inet.Execute(url,Command,Data,RequestHeaders)x
url Command Data RequestHeaders
. Command HTTP :
: GET : HEAD header : POST : PUT ) ( upload GET Execute IT
GetChunk .
:
Inet.Execute http://www.microsoft.com,GETx
: IT
: AccessType IT : : icUseDefault
: icDirect IT
: icNamedProxy
: Document Execute . Execute url .

: Password FTP : Procotol Execute 5 : : icUnknown


: icDefault
: icFTP FTP
: icHTTP HTTP
: icHTTP HTTP
: Proxy : RequestTimeOut IT . . ) ( OpenURL
) ( Execute StateChanged

: ResponseCode icError . : ResponseInfo : StillExecuting True . : URL OpenURL Execute : UserName - FTP

- Internet Transfer

FTP
FTP ) (
FTP . HTTP HTTP
IT .
FTP Login . Login ) Anonymous Login (
FTP .
. username password
IT . username ) ( blank IT anonymous
email passowrd .
: OpenURL OpenURL FTP . FTP
:
Text.text=Inet.OpenURL("ftp://ftp.microsoft.com",icString)x
FTP :
b()=Inet.OpenURL("ftp://ftp.microsft.com/test.zip",icByteArray)x
: Execute Execute FTP :
Inet.Execute(url,operation)x

url FTP operation FTP . IT


FTP :
DIR IT GetChunk .
GET
GetChunk .
FTP
.
FTP . anonymous FTP
download .
FTP :
: CD path path .
: CDUP .
: CLOSE FTP
: DELETE file1 file1
: DIR file1 file1
: MKDIR path path
: PUT file1 file2 file1 file2 .
: PWD .
: QUIT FTP
: GET file1 file2 file1 file2 .
: file2 RENAME file1 file1 file2
: RMDIR path path
: SIZE file1 file1
:
test.zip")x Inet.Execute("ftp://ftp.microsoft.com","GET

- WinSock

:
WinSock .
TCP UDP .
) Client/Server / ( TCP UDP
.

. :
Port Scanner Game Network Proxy Server Mail server Mail client Client-server chat

: TCP
) ( Transfer Control Protocol ) ( Connection )
( socket ) ( Computer Remote .
. TCP
.
Client IP Server ) ( Remote Host IP
) . ( Remote Port Connect .
Server )
( LocalPort ) . ( Listen
Client Server Accept .
.

: UDP
) ( User Datagram Protocol ) ( Connectionless . TCP
client server .
UDP .
UDP Local Port Client . Server
RemoteHost Client Remote Port Local Port Client
. .
: WinSock
1 : WinSock TCP
UDP . .
:
Server Client TCP .
) ( TCP TCP .
.

) ( Session UDP .
UDP .
2 :
Protocol WinSock sckTCPProtocol sckUDPProtocol .
:
WinSock.Protocol=sckTCPProtocol
3 : IP .
Control Panel/Network/Identification . Client Server
IP 127.0.0.1
ipconfig DOS Prompt IP .
4 : TCP TCP
Client . Server Server Listen . Client
Server Accept . Client
Server .
TCP :
Project Components Component Microsoft WinSock 6.0 .
WinSock tcpserver textbox txtSendData txtReceiveData . Form_Load :Tcpserver.LocalPort=1000
tcpserver.Listen
Client ConnectionRequest . . .
requestID :
(requestID As Long Private Sub tcpserver_ConnectionRequest(ByVal
tcpserver.Close sckClosed Then <> If tcpserver.State
tcpserver.Accept requestID
End Sub
Client Server . event Send :Tcpserver.SendData txtSendData.text
Client DataArrival . :(As Long Private Sub tcpserver_DataArrival(ByVal bytesTotal
Dim strData As String
strData tcpserver.GetData

txtReceiveData.Text = strData
End Sub
Form_Unload :Tcpserver.Close
TCP Client :
WinSock tcpclient . textbox txtsend txtreceive send . connect . Form_Load :tcpclient.RemoteHost=yourservernamex
tcpclient.RemotePort=1000
connect :tcpclient.Connect
send :tctclient.SendData txtsend.Text
DataArrival :(As Long Private Sub tcpclient_DataArrival(ByVal bytesTotal
Dim strData As String
strData tcpclient.GetData
txtreceive.Text = strData
End Sub
Form_Unload :Tcpclient.Close
Client-Server . exe
.
5 Server : .
WinSock . )
( instance ) ( Index Accept instance .
WinSock sckServer Index . intMax
Long Server . event Form_Load
:

intMax=0
sckServer(0).LocalPort=1000
sckServer(0).Listen
Index . Index
intMax intMax instance .
instance . ConnectionRequest
:
(Integer, ByVal requestID As Long Private Sub sckServer_ConnectionRequest(Index As
If Index = 0 Then
1 + intmax = intmax
Load sckServer(intmax)x
0 = sckServer(intmax).LocalPort
sckServer(Index).Accept requestID
End If
End Sub
6 : UDP UDP TCP UDP .
TCP WinSock Listen Connect
. UDP . WinSock
:
RemoteHost . RemotePort LocalPort Bind LocalPort Peer-to-Peer .
chat :
WinSock udppeerA . Protocol UDPProtocol . textbox txtsend txtreceive . Form_Load :udppeerA.RemoteHost=nameofpeerBx
udppeerA.RemotePort=1001
1002 udppeerA.Bind
event :udppeerA.SendData txtsend.text
DataArrival :Dim strData as String
strData udppeerA.GetData
txtreceive.Text=strData

UDP peerB RemoteHost PeerA


RemotePort 1002 Bind 1001 .

- WinSock
: WinSock
: ByteReceived ) ( receive . GetData
.
: LocalHostName . .
: LocalIP IP string . .
: LocalPort .
: Protocol WinSock .
: RemoteHost IP .
: RemoteHostIP IP :
- Client Connect IP
.
- Server Connection Request IP .
- UDP Arrival Data IP
.
: RemotePort .
: SocketHandle WinSock
WinSock . API WinSock
.
: State WinSock . State :
: sckClosed - .
: sckOpen - .
: sckListening -
: sckConnectionPending - 4
: sckResolvingHost -
: sckHostResolved - .
: sckConnecting -
: sckConnected - .
: sckClosing -
: sckError -
: WinSock
: Accept TCP Server .
ConnectionRequest .
: Bind LocalPort LocalIP .
: Close TCP listening socket .
: GetData Variant .
:
WinSock.GetData data[,type][,maxlen]x

data . data empty .


type :
vbString - - vbInteger - vbLong - vbSingle - vbDouble - vbDate - vbBoolean - vbError - vbByte
vbArray+vbByte
maxlen byte Array string .
Getdata Data Arrival TotalBytes . maxlen
TotalBytes
.
: Listen Listen . TCP .
: PeekData GetData .
TCP .
: SendData .
event : WinSock
: Close .
: Connect Server . :
Boolean)x Private Sub WinSock_Connect(ErrorOccurred As
ErrorOccurred : True Fail False
.
Connect error .
: ConnectionRequest .
TCP Server .
: DataArrival .
: Error ) Failed to Connect . ( Failed to Send
:
as String,scode as Long,source as String,helpfile as Private WinSock_Error(number as Integer,description
Long,canceldisplay as Boolean)x String,helpcontext as
number .
description .
source
: canceldisplay
: SendComplete Send .
: SendProgress . :
bytesRemaining As Long)x ,WinSock_SendProgress (bytesSent As Long
bytesSent bytesRemaining .

TAPI -

TAPI
TAPI Telephony API .
) Phone Dialer ( ) ( Dialup Networking
.

.

TAPI -

: Microsoft Telephony
Telephony .
) PSTN ( .
Telephony :

Multicast
VoIP

PSTN

Microsoft Telephony :

: TAPI
TAPI
. TAPI
) . ( Assisted Telephony
TAPI .
TAPI 2.x . TAPI 3.x
TAPI API C COM .
.
TAPI :
: TAPI Initialization - load TAPI dll Server TAPI TAPI
event .
: Session Control -
: Device Control -
: Media Control - stream

: TAPI Shutdown -
:

TAPI -

: TAPI
TAPI . :
- : TAPI .
.
- :
- : TAPI TAPI .
- : TAPI
.
: Event notification - event

TAPI -

TAPI :
Project References Microsoft TAPI 3.0 Type Library
.
objTAPI :
Dim objTapi As TAPI
Load Form objTAPI :
Set objTapi = New TAPI
TAPI .
TAPI :
Call objTapi.Initialize

- TAPI
:
TAPI
.
TAPI
.
error checking :
.
: -
Dim gobjAddress As ITAddress
As ITCollection Dim objCollAddresses
: objTapi objCollAddress -
Set objCollAddresses = objTapi.Addresses
: -
bFound = False
objCollAddresses.Count For indexAddr = 1 To
objCollAddresses.Item(indexAddr)x = Set objCrtAddress
Set objMediaSupport = objCrtAddress
objAddressCapabilities = objCrtAddress Set
nSelectedType ) x )If objMediaSupport.QueryMediaType
bFound = True
End If
Nothing = Set objAddressCapabilities
Set objMediaSupport = Nothing
Nothing = Set objCrtAddress
If bFound = True Then Exit For
Next indexAddr

: gobjAddress
objcollAddresses.Item(indexAddr)x = Set gobjAddress

- TAPI

: TAPI Event Handling


event event TAPI event handler
event TAPI .
.
:
TAPI Dim WithEvents gobjTapiWithEvents As
Attribute gobjTapiWithEvents.VB_VarHelpID = -1
glRegistrationToken As Long Dim

Const TAPI3_CALL_EVENTS =TE_CALLMEDIA Or


TE_CALLNOTIFICATION Or TE_CALLSTATE

: TAPI event eventfilter


TAPI3_CALL_EVENTS = objTapi.EventFilter
: event
Set gobjTapiWithEvents = objTapi
Boolean, fMonitor As Boolean Dim fOwner As
Long Dim lMediaTypes As Long, lCallbackInstance As
fOwner = True
fOwner = True
fMonitor = False
TAPIMEDIATYPE_AUDIO = lMediaTypes
lCallbackInstance = 1
,gobjTapi.RegisterCallNotifications(gobjAddress,fMonitor = glRegistrationToken
fOwner,lMediaTypes,lCallbackInstance)x

- TAPI

:
TAPI Initialization +
.
: ) ( ITBasicCallControl
Dim objCallControl As ITBasicCallControl
objCallControl = gobjReceivedCallInfo Set
: ) ( ITTerminalSupport
Dim objTerminalSupport As ITTerminalSupport
objTerminalSupport = gobjAddress Set
: objTerminalSupport
Dim objTerminal As ITTerminal
objTerminalSupport.GetDefaultStaticTerminal(lMediaType, dir)x = Set objTerminal
: objTerminalSupport
Set objTerminalSupport = Nothing
: objStreamControl
Dim objStreamControl As ITStreamControl
objStreamControl = objCallControl Set
for ITCollection
:
If Not (objStreamControl Is Nothing) Then
objITCollStreams As ITCollection Dim
objStreamControl.Streams = Set objITCollStreams

ITStream Dim nIndex As Long, objCrtStream As


For nIndex = 1 To objITCollStreams.Count
objITCollStreams.Item(nIndex)x = Set objCrtStream
Then If objCrtStream.MediaType = lMediaType
If objCrtStream.Direction = dir Then
objCrtStream.SelectTerminal(objTerminal)x Call
End If
End If
objCrtStream = Nothing Set
Next nIndex
Nothing = Set objITCollStreams
Set objStreamControl = Nothing
End If

: ( Make a Call )
. TAPI Initialization +

.
. TAPI Initialization
: CreateCall
nSelectedType,lMediaTypes)x ,gobjOrigAddress.CreateCall(strDestAddress = Set gobjCall
:
{
Select Terminal Code
}
: Connect
gobjCall.Connect (False)x
. False

- TAPI
:
.
. event
pEvent .
: event Handler TAPI ITCallNotificationEvent
If TapiEvent = TE_CALLNOTIFICATION Then
objCallNotificationEvent As ITCallNotificationEvent Dim
objCallNotificationEvent = pEvent Set
ITCallInfo Dim gobjReceivedCallInfo As
Set gobjReceivedCallInfo = objCallNotificationEvent.Call
objCallControl As ITBasicCallControl Dim
gobjReceivedCallInfo = Set objCallControl
objCallControl.Answer
End If

http://sheidaian.persianblog.com

You might also like