Hi Guys! Good Day. Need to ask some help again.
I am developing a client side application that writes a COMMANDS and listens a RESULT.
Now, the server side is made from perl codes..
The task is simple...
Declare Global Variable:
1. Connect to the ServerCode:Private _TcpClient As New TcpClient Private _NetStream As NetworkStream
2. Sends CommandCode:Private Sub Connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect.Click Try _TcpClient = New TcpClient _TcpClient.Connect("10.0.28.99", 7890) Catch ex As Exception Console.WriteLine(Err.ToString()) End Try End Sub
3. Receive Result automaticallyCode:Private Sub Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send.Click _NetStream = Nothing _NetStream = _TcpClient.GetStream Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("22,REGIST,000012\n") _NetStream.Write(sendBytes, 0, sendBytes.Length - 1) End Sub
4. Disconnect to the ServerCode:Private Sub ThreadOnRecieve Do Dim bytes(_TcpClient.ReceiveBufferSize) As Byte _NetStream.Read(bytes, 0, CInt(_TcpClient.ReceiveBufferSize)) Dim returndata As String = Encoding.ASCII.GetString(bytes) ReturnLabel.Text = returndata Loop End Sub
Now, the problem are:Code:Private Sub Disconnect _TcpClient.Close() End Sub
1. I Am definitely a newbie about TCP/IP
2. I could not send a command until i do this:
but, when i did that. my stream are gone and i am not able to send another command. And when i tried to reconnect again, the server no longer accepts me... seems that my previous connection was still up..Code:_NetStream.Flush() _NetStream.Close()
Hope you can enlightens me.. Thanks guys!![]()





Reply With Quote
