Sub Process_Globals
Dim AStreams As AsyncStreams
Dim Server As ServerSocket
Dim Socket1 As Socket
'Declaramos las variables para ip y puerto Correspondiente
Dim port As String
Dim ServerIp As String
End Sub
Sub Globals
Dim Button1 As Button
Dim Button2 As Button
Dim txtTexto As EditText
Dim EditText1 As EditText
EditText1.Initialize ("EditText1")
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
'aqui tu puerto
port = 5007
'aqui tu ip
ServerIp="192.168.1.121"
End Sub
Sub connet
Try
Socket1.Initialize("Socket1")
Socket1.Connect(ServerIp ,port, 20000)
Catch
ToastMessageShow( "No conectó!", True)
End Try
End Sub
Sub Socket1_Connected (Connected As Boolean)
If Connected = True Then
ToastMessageShow( "Conectado!", True)
AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"Astreams")
End If
End Sub
Sub send_data(data As String)
If AStreams.IsInitialized = True Then
Dim buffer() As Byte
data=data
buffer = data.GetBytes("UTF8")
AStreams.Write(buffer)
End If
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
ToastMessageShow( msg, True)
End Sub
Sub AStreams_Error
ToastMessageShow( LastException.Message, True)
End Sub
Sub Button1_Click
connet
End Sub
Sub Button2_Click
'declaro la cadena a enviar
Dim cadena As String
'y le asigno su valor en este caso un edittext
cadena = EditText1.text
'envio la cadena
send_data(cadena)
End Sub
Sub EditText1_TextChanged (Old As String, New As String)
'esto sirve para enviar en tiempo real los cararcteres al escribirlos en el editetext
Dim pline As String
pline = EditText1.Text
If pline.Length > 40 Then
EditText1.Text = pline.SubString2(0,39)
EditText1.SelectionStart = 39
ToastMessageShow("40 character limit",False)
End If
send_data(pline)
End Sub