Eu fiz um programa enviar dados para um roteador tudo funciona bem.
Tem hora os dados trava na hora envio,
Aqui esta o programa.Se tem error eu não consigo detectar
Agradeço ajuda.
Imports System.Net.Sockets
Imports System.Text
Imports System.Net.WebRequestMethods
Public Class Form1
Dim out As String
Dim isConnected As Boolean
Dim ipadd As String
Public my_client As System.Net.Sockets.TcpClient 'for router connection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TrackBar1.Value = 1500
TextBox5.Text = 1500
TrackBar2.Value = 1500
TextBox1.Text = 1500
isConnected = False
End Sub
Private Sub Form1_keydown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If isConnected = True Then
Select Case e.KeyCode
Case Keys.W
Button7.Visible = False
out = "PC" & "A"
'SendStream(out)
Case Keys.Z
Button8.Visible = False
out = "PC" & "B"
'SendStream(out)
Case Keys.S
Button10.Visible = False
out = "PC" & "C"
'SendStream(out)
Case Keys.A
Button9.Visible = False
'out = "PC" & "D"
SendStream(out)
Case Keys.M
TrackBar1.Value = TrackBar1.Value + 1
TextBox5.Text = TrackBar1.Value
out = "PC" & "E" & (TextBox5.Text)
'SendStream(out)
Case Keys.N
TrackBar1.Value = TrackBar1.Value - 1
TextBox5.Text = TrackBar1.Value
out = "PC" & "E" & (TextBox5.Text)
'SendStream(out)
Case Keys.V
TrackBar2.Value = TrackBar2.Value + 1
TextBox1.Text = TrackBar2.Value
out = "PC" & "E" & (TextBox1.Text)
'SendStream(out)
Case Keys.B
TrackBar2.Value = TrackBar2.Value - 1
TextBox1.Text = TrackBar2.Value
out = "PC" & "E" & (TextBox1.Text)
'SendStream(out)
End Select
End If
End Sub
Private Sub Form1_keyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If isConnected = True Then
Select Case e.KeyCode
Case Keys.W
Button7.Visible = True
out = "PC" & "E"
'SendStream(out)
Case Keys.Z
Button8.Visible = True
out = "PC" & "E"
'SendStream(out)
Case Keys.S
Button10.Visible = True
out = "PC" & "E"
'SendStream(out)
Case Keys.A
Button9.Visible = True
out = "PC" & "W"
'SendStream(out)
End Select
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ((TextBox3.Text = "") Or (TextBox4.Text = "")) Then
'hist("Enter host and IP")
Else
Try
Button1.Enabled = False
Button2.Enabled = True
SendStream("Cliente Conectado..")
Button37.BackColor = Color.Red
Button31.BackColor = Color.Red
Catch ex As Exception
End Try
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SendStream("Cliente desconectado..")
Button37.BackColor = Color.Lime
Button31.BackColor = Color.Lime
Button2.Enabled = False
Button1.Enabled = True
isConnected = False
End Sub
Sub SendStream(ByVal out As String)
Try
Dim my_client As New TcpClient(TextBox3.Text, TextBox4.Text)
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(out)
Dim stream As NetworkStream = my_client.GetStream()
stream.Write(data, 0, data.Length)
stream.Close()
my_client.Close()
Catch e As ArgumentNullException
Catch e As SocketException
End Try
isConnected = True
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
SendStream(out)
End Sub
End Class
Pergunta
Césarvix
Ola Amigos tudo bem
Eu fiz um programa enviar dados para um roteador tudo funciona bem.
Tem hora os dados trava na hora envio,
Aqui esta o programa.Se tem error eu não consigo detectar
Agradeço ajuda.
Link para o comentário
Compartilhar em outros sites
0 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.