H
Helroos
Guest
Hello, Im trying to make a tcp connection between a server and a client.
The client sends comands to the server and reiceve informations, the server sends informations and reiceve comands.
I followed these 2 tutorials:
Vb.net creare il lato client(tcp/ip) - YouTubeVb.net socket creare Il lato server (tcp/ip) - YouTube
But Im getting an error on Writing in the networkstream. [Write(Bytes,0,Bytes.Length]
Client:
Imports System.Net
Imports System.Net.Sockets
Imports System.Text.UTF8Encoding
Imports System.Threading
Public Class Form1
Dim Client As TcpClient
Dim Server As TcpListener
Dim Datas As NetworkStream
Dim Listen As New Thread(Sub()
While True
If Client.Available Then
Dim Bytes(Client.Available - 1) As Byte
Datas.Read(Bytes, 0, Bytes.Length)
Label1.Text = UTF8.GetString(Bytes)
End If
End While
End Sub)
Private Sub Form1_Load() Handles MyBase.Load
Dim ipcol As New Collection
Dim ipe As IPHostEntry = Dns.GetHostEntry("helroosdc.no-ip.com")
Dim ipa() As IPAddress = ipe.AddressList
ipcol.Add(ipa(1).ToString)
Client = New TcpClient
Client.Connect(ipcol(1), 1604)
Do Until Client.Connected
Thread.Sleep(100)
Loop
Datas = Client.GetStream
Listen.Start()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Try
Dim Bytes As Byte() = UTF8.GetBytes(TextBox1.Text)
Datas.Write(Bytes, 0, Bytes.Length)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Server:
Imports System.Text.UTF8Encoding
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Public Class Form1
Dim Client As TcpClient
Dim Server As TcpListener
Dim Datas As NetworkStream
Dim WithEvents Comand As New TextBox With {.Visible = False}
Dim ReadData As New Thread(Sub()
While True
If Client.Available Then
Dim Bytes(Client.Available - 1) As Byte
Datas.Read(Bytes, 0, Bytes.Length)
Select Case UTF8.GetString(Bytes)
Case "Info"
End Select
MsgBox(UTF8.GetString(Bytes))
End If
End While
End Sub)
Dim AcceptConnection As New Thread(Sub()
While True
If Server.Pending Then
Client = Server.AcceptTcpClient
Datas = Client.GetStream
End If
End While
End Sub)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Server = New TcpListener(New IPEndPoint(IPAddress.Any, 1604))
Server.Start()
AcceptConnection.Start()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Bytes As Byte() = UTF8.GetBytes(TextBox2.Text)
Datas.Write(Bytes, 0, Bytes.Length)
End Sub
End Class
Error in on
Datas.Write(Bytes, 0, Bytes.Length)
Can you help me please? Thanks in advance for any help/tip.
Continue reading...
The client sends comands to the server and reiceve informations, the server sends informations and reiceve comands.
I followed these 2 tutorials:
Vb.net creare il lato client(tcp/ip) - YouTubeVb.net socket creare Il lato server (tcp/ip) - YouTube
But Im getting an error on Writing in the networkstream. [Write(Bytes,0,Bytes.Length]
Client:
Imports System.Net
Imports System.Net.Sockets
Imports System.Text.UTF8Encoding
Imports System.Threading
Public Class Form1
Dim Client As TcpClient
Dim Server As TcpListener
Dim Datas As NetworkStream
Dim Listen As New Thread(Sub()
While True
If Client.Available Then
Dim Bytes(Client.Available - 1) As Byte
Datas.Read(Bytes, 0, Bytes.Length)
Label1.Text = UTF8.GetString(Bytes)
End If
End While
End Sub)
Private Sub Form1_Load() Handles MyBase.Load
Dim ipcol As New Collection
Dim ipe As IPHostEntry = Dns.GetHostEntry("helroosdc.no-ip.com")
Dim ipa() As IPAddress = ipe.AddressList
ipcol.Add(ipa(1).ToString)
Client = New TcpClient
Client.Connect(ipcol(1), 1604)
Do Until Client.Connected
Thread.Sleep(100)
Loop
Datas = Client.GetStream
Listen.Start()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Try
Dim Bytes As Byte() = UTF8.GetBytes(TextBox1.Text)
Datas.Write(Bytes, 0, Bytes.Length)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Server:
Imports System.Text.UTF8Encoding
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Public Class Form1
Dim Client As TcpClient
Dim Server As TcpListener
Dim Datas As NetworkStream
Dim WithEvents Comand As New TextBox With {.Visible = False}
Dim ReadData As New Thread(Sub()
While True
If Client.Available Then
Dim Bytes(Client.Available - 1) As Byte
Datas.Read(Bytes, 0, Bytes.Length)
Select Case UTF8.GetString(Bytes)
Case "Info"
End Select
MsgBox(UTF8.GetString(Bytes))
End If
End While
End Sub)
Dim AcceptConnection As New Thread(Sub()
While True
If Server.Pending Then
Client = Server.AcceptTcpClient
Datas = Client.GetStream
End If
End While
End Sub)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Server = New TcpListener(New IPEndPoint(IPAddress.Any, 1604))
Server.Start()
AcceptConnection.Start()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Bytes As Byte() = UTF8.GetBytes(TextBox2.Text)
Datas.Write(Bytes, 0, Bytes.Length)
End Sub
End Class
Error in on
Datas.Write(Bytes, 0, Bytes.Length)
Can you help me please? Thanks in advance for any help/tip.
Continue reading...