Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

TCPClient - send data and receive data

Posted on 2012-09-20
1
Medium Priority
?
640 Views
Last Modified: 2012-11-20
Hi Experts Exchange,

I am using VB.Net. I need to send data to tcpclient and get the response data from the same. It should work from a button. Following command coded in Button click event

-----------------
        Dim response As String
        Dim client As New TcpClient()
        client.Connect("10.91.12.240", "8400")
        Dim ns As NetworkStream = client.GetStream()
        Dim streamWriter As New StreamWriter(ns)
        Dim request As String
        Dim numberOfBytesRead As Integer = 0
        Dim myReadBuffer(1024) As Byte
        Dim myCompleteMessage As StringBuilder = New StringBuilder()

        request = "<xml>" _
                    & "<equipment-id>ENTRY</equipment-id> " _
                    & "<request-type>get-tag</request-type> " _
                    & "<request-code>1</request-code>" _
                    & "<ack>0001</ack>" _
                    & "</xml>"
        streamWriter.WriteLine(request)
        streamWriter.Flush()
        Do
            numberOfBytesRead = ns.Read(myReadBuffer, 0, myReadBuffer.Length)
            myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead))
        Loop Until ns.DataAvailable

       response = myCompleteMessage.ToString

        client.Close()
        txtContTag.Text = response

-----------------------------------------

It is not working, I am writing this network coding first time, please help with process and coding pattern.

Regards,
Gnanesh
0
Comment
Question by:angnanesh
1 Comment
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 1500 total points
ID: 38417645
Here's a simple article showing TCP Client/Server communications in VB.net:
http://www.eggheadcafe.com/articles/20020323.asp

Hope that helps.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question