Hello All,
I am wanting to transfer messages between a VB.NET application (App1) and a VB.NET application on a hand held device (PDA) (App2)
I can transfer data from 1 to the other, although I cant seem to keep the server session (App1) open and continuley listening for incoming connections.
Each time data is sent to the server (App1) from the client (App2) the server sends back a reply and then closes.
Im sure this is probably something simple, although I have been trying it for a while now and never seem to get anywhere.
The code I currently have is as follows:
Server Code (App1)
Thank you in advance for your help.
I am wanting to transfer messages between a VB.NET application (App1) and a VB.NET application on a hand held device (PDA) (App2)
I can transfer data from 1 to the other, although I cant seem to keep the server session (App1) open and continuley listening for incoming connections.
Each time data is sent to the server (App1) from the client (App2) the server sends back a reply and then closes.
Im sure this is probably something simple, although I have been trying it for a while now and never seem to get anywhere.
The code I currently have is as follows:
Server Code (App1)
VB.NET:
Imports System.Net.Sockets
Imports System.Text
Class TCPSrv
SharedSub Main()
' Must listen on correct port- must be same as port client wants to connect on.
Const portNumber AsInteger = 8000
'Dim ipAdd As System.net.IPAddress = 127.0.0.1
Dim tcpListener AsNew TcpListener(portNumber)
tcpListener.Start()
Console.WriteLine("Waiting for connection...")
Try
'Accept the pending client connection and return a TcpClient initialized for communication.
Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
Console.WriteLine("Connection accepted.")
' Get the stream
Dim networkStream As NetworkStream = tcpClient.GetStream()
' Read the stream into a byte array
Dim bytes(tcpClient.ReceiveBufferSize) AsByte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Return the data received from the client to the console.
Dim clientdata AsString = Encoding.ASCII.GetString(bytes)
Console.WriteLine(("Client sent: " + clientdata))
Dim responseString AsString = "Connected to server."
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(responseString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Console.WriteLine(("Message Sent /> : " + responseString))
'********************************
'* Code needs to be added in here somewhere to continusly listen for incoming data
'********************************
tcpClient.Close()
tcpListener.Stop()
Console.WriteLine("exit")
Console.ReadLine()
Catch e As Exception
Console.WriteLine(e.ToString())
Console.ReadLine()
EndTry
EndSub
EndClass
Thank you in advance for your help.
Last edited by a moderator: