Actually I create an connection between windows-clients and a linux server using vb.net for the client and netcat for the server.
The problem is that I cannot receive anything using client_receive(), because I cannot send back data from the server to the client inside the open netcat socket connection. Also I am looking for a way to not directly respond to an client - rather time-independent. The connection needs to keep open and the server can say anything to an connected client using e.g. echo '$message' > /dev/tcp/client.ip/4000 in combination with screen. The important thing is that it needs to be the same connection, no new.
With the following code I am able to send strings to an port netcat is listening to:
Dim stream As NetworkStream
Dim streamw As StreamWriter
Dim streamr As StreamReader
Dim myclient As New TcpClient
Dim IP As String = "example.com"
Dim Port As Integer = 4000
Public Sub client_send(ByVal text As String)
streamw.WriteLine(text)
streamw.Flush()
End Sub
Public Function client_receive() As String
client_receive = streamr.ReadLine
End Function
Private Sub Welcome_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
myclient.Connect(IP, Port)
stream = myclient.GetStream
streamw = New StreamWriter(stream)
streamr = New StreamReader(stream)
Catch
End Try
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles iamonline.Tick
client_send("ItzMe")
MessageBox.Show(client_receive)
End Sub
We send ItzMe every 5 seconds to the port 4000/tcp.
In the netcat screen we see:
ItzMe
ItzMe
...
Update #1: Changed Timer1
Update #2: Detailed the question