Hi
could any one have an idea about send string text from B4A into vb.net
I have already complete the first part is send string text from vb.net into B4A and it successfully done.
But I can not understand what is the code should be to send string text from B4A into vb.net
here is my code for B4A
what is the code should be in btn_send to send the text into the vb.net ?
Here is my vb.net code
Dose any one have any idea? ... plz help I am new in B4A
Modify my code ..plz
could any one have an idea about send string text from B4A into vb.net
I have already complete the first part is send string text from vb.net into B4A and it successfully done.
But I can not understand what is the code should be to send string text from B4A into vb.net
here is my code for B4A
B4X:
'Activity module
Sub Process_Globals
Dim ServerSocket1 As ServerSocket
Dim Socket1 As Socket
Dim Timer1 As Timer
Dim InputStream1 As InputStream
' Dim OutputStream1 As OutputStream
Dim raf As RandomAccessFile
End Sub
Sub Globals
Dim lblName As Label
Dim lbl_connection As Label
Dim txt_recive As EditText
Private btn_send As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Timer1.Initialize("Timer1", 200)
File.MakeDir(File.DirRootExternal, "android") 'probably already exists
End If
'Initialize the server socket if it is not initialized.
'ServerSocket1 will not be initialized when FirstTime=True and after the user
'closed the activity and then opened it again (by pressing on the back key)
If ServerSocket1.IsInitialized = False Then
ServerSocket1.Initialize(2222, "ServerSocket1")
End If
ToastMessageShow("My IP: " & ServerSocket1.GetMyIP, True)
Activity.LoadLayout("1")
End Sub
Sub ServerSocket1_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
Socket1 = NewSocket
Timer1.Enabled = True
InputStream1 = Socket1.InputStream
' OutputStream1 = Socket1.OutputStream
lbl_connection.Text= "Connected"
ToastMessageShow("Connected", True)
Else
Msgbox(LastException.Message, "Error connecting")
End If
ServerSocket1.Listen 'Continue listening to new incoming connections
End Sub
Sub Activity_Resume
ServerSocket1.Listen
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
Timer1.Enabled = False
Socket1.Close
ServerSocket1.Close 'stop listening
End If
End Sub
Sub Timer1_Tick
Dim BC As ByteConverter
If InputStream1.BytesAvailable > 0 Then
Timer1.Enabled = False
Dim buffer(8192) As Byte
raf.Initialize3(buffer, True)
InputStream1.ReadBytes(buffer, 0, buffer.Length)
txt_recive.Text=(BC.StringFromBytes(buffer,"UTF-8"))
Timer1.Enabled = True
End If
End Sub
Sub btn_send_Click
' what is the code should be here to send string text into the text box in the vb.net
End Sub
what is the code should be in btn_send to send the text into the vb.net ?
Here is my vb.net code
B4X:
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Public Class Form1
Dim ip As IPAddress = IPAddress.Parse("127.0.0.1")
' the port must be the same in client ans server
Dim port As Integer = 2222
Dim sock As New TcpClient()
Dim Listener As New TcpListener(2222)
Dim Client As New TcpClient
Dim Message As String = ""
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
ip = IPAddress.Parse(TextBox_ip.Text)
port = TextBox_port.Text
sock.Connect(ip, port)
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
sock.Client.Send(System.Text.Encoding.UTF8.GetBytes(TextBox1.Text))
End Sub
Private Sub Listening()
Listener.Start()
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Listener.Stop()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim ListThread As New Thread(New ThreadStart(AddressOf Listening))
ListThread.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Listener.Pending = True Then
Message = ""
Client = Listener.AcceptTcpClient()
Dim Reader As New StreamReader(Client.GetStream())
While Reader.Peek > -1
Message = Message + Convert.ToChar(Reader.Read()).ToString
End While
MsgBox(Message, MsgBoxStyle.OkOnly)
End If
End Sub
End Class
Dose any one have any idea? ... plz help I am new in B4A
Modify my code ..plz