473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Receiving data back to Vb .net program

with this code I am trying to see the data being return thru port 10001, looks like no data is returned.. Can anybody see any problems with it. I am very very new to this .net stuff, so any help would be greatly appreciated.
Thanks


Expand|Select|Wrap|Line Numbers
  1. Imports System
  2. Imports System.Net.Sockets
  3. Imports System.Text
  4.  
  5. Public Module lantest1
  6.     Public Sub Main()
  7.         ' Must listen on correct port- must be same as port client wants to connect on.
  8.         Const portNumber As Integer = 10001
  9.         Dim tcpListener As New TcpListener(portNumber)
  10.         tcpListener.Start()
  11.         Console.WriteLine("Waiting for connection...")
  12.         Try
  13.             'Accept the pending client connection and return 
  14.             'a TcpClient initialized for communication. 
  15.             Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
  16.             Console.WriteLine("Connection accepted.")
  17.             ' Get the stream
  18.             Dim networkStream As NetworkStream = tcpClient.GetStream()
  19.             ' Read the stream into a byte array
  20.             Dim bytes(tcpClient.ReceiveBufferSize) As Byte
  21.             networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
  22.             ' Return the data received from the client to the console.
  23.             Dim clientdata As String = Encoding.Default.GetString(bytes)
  24.             Console.WriteLine(("Client sent: " + clientdata))
  25.             Console.WriteLine("Data s/b here it think.")
  26.             Console.ReadLine()
  27.             Dim responseString As String = "Connected to server."
  28.             Dim sendBytes As [Byte]() = Encoding.Default.GetBytes(responseString)
  29.             networkStream.Write(sendBytes, 0, sendBytes.Length)
  30.             Console.WriteLine(("Message Sent /> : " + responseString))
  31.             'Any communication with the remote client using the TcpClient can go here.
  32.             'Close TcpListener and TcpClient.
  33.             tcpClient.Close()
  34.             tcpListener.Stop()
  35.             Console.WriteLine("exit")
  36.             Console.ReadLine()
  37.         Catch e As Exception
  38.             Console.WriteLine(e.ToString())
  39.             Console.ReadLine()
  40.         End Try
  41.     End Sub
  42.  
  43. End Module
May 5 '11 #1
0 792

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Jim H | last post by:
I have a UDP socket that sends out a request on a multicast socket and waits for a response. This client is not listening on a multicast IP but the local IP. The server (UNIX) responds to the...
7
by: marfi95 | last post by:
Hi all, I'm stuck and hope someone out there knows how to get around this. I have to interface with a 3rd party vendor win32 dll and on one of their calls, they are returning a bunch of data...
1
by: atefe | last post by:
hi,every one i want to transmit data from a pic microcontroller to a pc . i need visual basic 6 codes for receiving data. would you mind helping me? thanks alot
2
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, When an external resouce programmatically post the XML document as content of http post request, and at server-side, I can read the XML data from http request's body. Just like this...
2
by: pauland80 | last post by:
Hello, My soft passively listen to a device sending +- 300 bytes of data each second. After several hours of work, the soft abruptly stops receiving data without any error, (while the device...
8
by: dadalos | last post by:
Hello; I'm having a problem with receiving data from serial port. There's an eventhandler(datareceived) and I'm monitoring the answer from the serial port to a text box in the eventhandler. There's...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
10
by: John Salerno | last post by:
I wrote some pretty basic socket programming again, but I'm still confused about what's happening with the buffer_size variable. Here are the server and client programs: -------------- from...
0
by: =?Utf-8?B?QmlsbCBC?= | last post by:
I am having a problem where no data is being returned from an Axis web service. I can invoke the service just fine and it does not give any errors, but the data objects do not hold any data. If I...
1
Airslash
by: Airslash | last post by:
Hello, The problem is that my server is not receiving data. The code below are the various classes I designed around sockets. It will be big... I have run the code with the debugger, and I see...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.