Merih Forum Programlama ve yazılım algoritmalar Genel vb [Basit] Server + Client Kodları

  • Toplam: 0 Oy - Ortalama: 0
  • 1
  • 2
  • 3
  • 4
  • 5
[Basit] Server + Client Kodları

 
#1

Server :
Kod:
Imports System.Net, System.Net.Sockets, System.Text.UTF7Encoding

Public Class Form1
Dim server As TcpListener
Dim client As TcpClient
Dim flusso As NetworkStream
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ip As String
If CheckBox1.Checked Then
Dim ipcol As New Collection
Dim ipe As IPHostEntry = System.Net.Dns.GetHostEntry(TextBox1.Text)
Dim ipa() As IPAddress = ipe.AddressList
For i = 0 To ipa.GetUpperBound(0)
ipcol.Add(ipa(i).ToString)
Next
ip = ipcol.Item(1)
Else
ip = "127.0.0.1"
End If
client = New TcpClient
client.Connect(ip, 8080)
If client.Connected = True Then
flusso = client.GetStream
Timer1.Start()
Label1.Text = "Connected"
Else
MsgBox("Connection Error", MsgBoxStyle.Critical, "ERROR")
Label1.Text = "Disconnected"

End If

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If client.Available > 0 Then
Dim t(client.Available - 1) As Byte
flusso.Read(t, 0, t.Length)
Dim testo As String = UTF7.GetString(t)
RichTextBox1.Text = testo
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim t() As Byte = UTF7.GetBytes("Info")
flusso.Write(t, 0, t.Length)


End Sub
End Class


Client ( Oluşturucu ):
Kod:
Imports System.Net
Imports System.Net.Sockets
Imports System.Text.UTF7Encoding
Imports System.IO
Public Class Form1
Dim server As TcpListener
Dim client As TcpClient
Dim flusso As NetworkStream
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
server = New TcpListener(IPAddress.Any, 8080)
server.Start()
Label1.Text = "In Attesa..."
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If server.Pending Then
client = server.AcceptTcpClient()
Label1.Text = "Connesso!"
flusso = client.GetStream
Timer1.Stop()
Timer2.start()
End If
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If client.Available > 0 Then
Dim t(client.Available - 1) As Byte
flusso.Read(t, 0, t.Length)
Dim testo As String = System.Text.UTF7Encoding.UTF7.GetString(t)
TextBox1.Text = testo
Select Case TextBox1.Text
Case "info"
Dim temp() As Byte = UTF7.GetBytes(My.Computer.Info.OSFullName & vbCrLf & My.Computer.Info.OSVersion & vbCrLf & My.Computer.Info.OSPlatform & vbCrLf & "Dati ricevuti correttamente")
flusso.Write(t, 0, t.Length)


End Select


End If
End Sub



Ara
Cevapla


[-]
Hızlı Cevap

İnsan Doğrulama:
Aşağıda görünen onay kutusunu işaretleyiniz. Bu işlem otomatik spam kayıtları önlemek için kullanılır.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Konuyu Okuyanlar:
1 Ziyaretçi

   
Türkçe Çeviri: MCTR, Forum Yazılımı: MyBB, © 2002-2021 MyBB Group.  



Merih Forum® bilgi paylaşım platformu. 2015-2020 Tüm hakları saklıdır.