Hey there,
This isn't the place to ask such questions.
You should start a new thread on the Basic4Android Updates & Questions.
However, i have some code lying around written in Vb.net;
Imports System.Net
Imports System.Net.Sockets
Public Class Form1
Dim sock As New TcpClient()
Dim ip As IPAddress = IPAddress.Parse("127.0.0.1")
Dim port As Integer = 10130
Private Sub connect()
If TextBox_IP.Text = "localhost" Then
TextBox_IP.Text = "127.0.0.1"
End If
ip = IPAddress.Parse(TextBox_IP.Text)
port = TextBox_Port.Text
Try
sock.Connect(ip, port)
lblState.Text = "Connected!"
Btn_Connect.Text = "Disconnect!"
Catch ex As Exception
MsgBox("Unable to connect to server. Other device might be offline.")
lblState.Text = "Disconnected!"
Btn_Connect.Text = "Connect!"
End Try
End Sub
Private Sub dat(ByVal dat As String)
Dim nstream As NetworkStream = sock.GetStream()
Dim bit As [Byte]() = System.Text.Encoding.ASCII.GetBytes(dat)
nstream.Write(bit, 0, bit.Length)
End Sub
Private Sub Btn_Connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Connect.Click
connect()
End Sub
Private Sub Btn_Path_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
dat("0*" + TextBox_Path.Text)
End Sub
Private Sub Btn_Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
dat("1*" + TextBox_Send.Text)
End Sub
Private Sub Btn_OpenCD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
dat("2*")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
That's the server on vb.net however it doesn't work asynchrounosly.
However this server will connect to your device.
In Basic4Android you could also use TCP/IP sockets to connect to the device.
There are enough examples here on the forum.
Some things you'd need to know:
- Only works on LAN
- connect to internal IP
You should take a look at sockets, asyncstreams.
If you could send data from your server to you client (android), you are able to use async streams to receive the data and decode it.
Next you can execute commands from the data with a select case. (You could convert the bytes to text)
Kind regards,
Tomas