Hi all,
can you help me how to give ip address and port number dynamically in tcp client programming(ie for button click and form load give ipaddress and port number one time).please help me.
[edit from OP's response]
Whats my exact issue is I used Form load and button click events in tcp client programming in that i gave ipaddress and port number 2 times(ie one time for form load event and one time for button click event).But i want give ipaddress and port number dynamically for form load and button click event at one time.
my code is
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim RxResponse, RxResponse1, RxResponse2, RxResponse3, RxResponse4 As String
Dim TxCommand1 As String
Dim Buffer1() As Byte
Dim InBuff(1532) As Byte
Try
client.Connect(IpAddress, PortNum)
Catch ex As Exception
MsgBox("Connection with the server failed, and the following code was returned:" & ex.Message, 0, "connection error")
Exit Sub
End Try
TxCommand1 = "01ff000a44200000046a0200"
Buffer1 = System.Text.Encoding.Default.GetBytes(TxCommand1.ToCharArray)
client.GetStream().Write(Buffer1, 0, Buffer1.Length)
While Not client.GetStream().DataAvailable()
Application.DoEvents()
End While
If client.GetStream().DataAvailable() Then
client.GetStream().Read(InBuff, 0, InBuff.Length)
RxResponse = System.Text.Encoding.Default.GetString(InBuff)
RxResponse1 = Mid(RxResponse, 5, 8)
RxResponse2 = Mid(RxResponse1, 1, 4)
RxResponse3 = Mid(RxResponse1, 5, 4)
RxResponse4 = RxResponse3 & RxResponse2
TextBox4.Text = CStr(ConvertHexToSingle(RxResponse4))
End If
client.GetStream().Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Buffer(), Buffer1() As Byte
Dim TxCommand3, TxCommand2, TxCommand4, TxCommand5 As String
Dim sal, smart As Integer
Dim sal1, sal2, trak2, trak1, trak3, trak4 As String
Try
client.Connect(IpAddress, PortNum)
Catch ex As Exception
MsgBox("Connection with the server failed, and the following code was returned:" & ex.Message, 0, "connection error")
Exit Sub
End Try
Dim trak As Single
sal = CInt(Val(TextBox3.Text))
sal1 = Hex$(sal)
smart = Len(sal1)
Select Case smart
Case 1
sal2 = "000" & sal1
Case 2
sal2 = "00" & sal1
Case 3
sal2 = "0" & sal1
Case Else
sal2 = sal1
End Select
TxCommand2 = "03ff000a4420000004560100"
TxCommand3 = TxCommand2 & sal2
Buffer = System.Text.Encoding.Default.GetBytes(TxCommand3.ToCharArray)
client.GetStream().Write(Buffer, 0, Buffer.Length)
While Not client.GetStream().DataAvailable()
Application.DoEvents()
End While
trak = CSng(TextBox2.Text)
trak1 = ConvertSingleToHex(trak)
trak2 = Mid(trak1, 1, 4)
trak3 = Mid(trak1, 5, 4)
trak4 = trak3 & trak2
TxCommand4 = "03ff000a4420000000000200"
TxCommand5 = TxCommand4 & trak4
Buffer1 = System.Text.Encoding.Default.GetBytes(TxCommand5.ToCharArray)
client.GetStream().Write(Buffer1, 0, Buffer1.Length)
While Not client.GetStream().DataAvailable()
Application.DoEvents()
End While
client.GetStream().Close()
client.Close()
End Sub
please help me...................
[/edit]