25 05 2007

UDP

1 - UDP : Basit bağlantı programları yazmakta
Winsock1.Protocol = sckUDPProtocol

Private Sub Form_Load()
Randomize ‘ Rastlantısal olarak kullanıcı ismi oluşturmak
Text3.Text = "Kullanıcı - " & Int(100 * Rnd + 1)
End Sub

Private Sub Clie_Click() ‘ Server’a bağlantı
Dim adres As String
adres = InputBox("Server'ın IP Adresini Giriniz :", "Bağlantı", "127.0.0.1")
With Winsock1
.RemoteHost = adres
.RemotePort = 1002
.Bind 1001
End With
Form1.Caption = "PeerB"
End Sub

Private Sub serv_Click() ‘ Server moda geçiş
With Winsock1
.RemoteHost = LocalHostIP
.RemotePort = 1001
.Bind 1002
End With
Form1.Caption = "PeerA"
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer) ‘ Bilgi gönderme
If KeyAscii = 13 Then
Winsock1.SendData Text3.Text & " :" & Text2.Text
Text1.Text = Text1.Text & Text3.Text & " :" & Text2.Text & vbCrLf
Text2.Text = ""
End If
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Accept requestID ‘ Bağlantı kabulü
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Veri As String
Winsock1.GetData Veri ‘ Bilgi alınışı
Text1.Text = Text1.Text & Veri & vbCrLf
End Sub