Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Network
DAFTAR ISI
• SOCKET pada VB NET
Pemrograman SOCKET pada vb net
server
client
Visual Basic networking applications using sockets
System.Net.Sockets
class
TcpListener
class
TcpClient
5 step to establish TCP server with VB.net
Step four
processing phase, in which the server and the client communicate via
methods Receive and Send of class Socket.
Module Module1
'---port number to use for listening---
Const portNo As Integer = 5000
Sub Main()
Dim localAdd As System.Net.IPAddress = System.Net.IPAddress.Parse("127.0.0.1")
'---listen at the local address---
Dim listener As New TcpListener(localAdd, portNo)
listener.Start()
'---Accepts connection ---
Dim tcpClient As TcpClient = listener.AcceptTcpClient()
'--receive data---
Dim ns As NetworkStream = tcpClient.GetStream
Dim data(tcpClient.ReceiveBufferSize) As Byte
'---read incoming stream; Read()
Dim numBytesRead As Integer = ns.Read(data, 0, CInt(tcpClient.ReceiveBufferSize))
End Sub
End Module
5 step to establish TCP Client with VB.net
first step,
create an object of class TcpClient
TcpClient client = New TcpClient()
client.Connect( serverAddress, serverPort )
step two,
the TcpClient uses its method GetStream to get a Network-
Stream so that it can write to and read from the server.
third step
the processing phase, in which the client and the server communicate.
In this phase, the client uses methods Read, ReadByte, Write and WriteByte of
class NetworkStream
step four
client to close the connection
by calling method Close of the NetworkStream object.
TCP/IP Client VB Net
Sub Main()
Dim tcpclient As New TcpClient
'---connect ke server---
tcpclient.Connect("127.0.0.1", 5000)
'---menggunakan obj NetworkStream untuk send and receive data
Dim ns As NetworkStream = tcpclient.GetStream
End Module
Writing a simple UDP client
imports System.Net
imports System.Net.Sockets
imports System.Text
imports System.IO
udpClient.Connect(tbHost.Text, 8080)
udpClient.Send(sendBytes, sendBytes.Length)
End sub
Writing a simple UDP server
imports System.Threading
imports System.Net
imports System.Net.Sockets
imports System.Text