iOS Question Sending string to server

Fatjo

New Member
Licensed User
Here is the code if it can help ..


Sub Process_Globals
Dim AStreams As AsyncStreams
Dim Server As ServerSocket
Dim socket1 As Socket

Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Dim EditText1 As TextView
Private hd As HUD
End Sub


Private Sub Application_Start (Nav As NavigationController)
'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
Page1.RootPanel.Color = Colors.White
NavControl.ShowPage(Page1)
Activity_Create(True)
End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Server.Initialize(8565, "Server")
Server.Listen
socket1.Initialize("socket1")
socket1.Connect("192.168.0.233",8565,30000)
Log("MyIp = " & Server.GetMyIP)
End If
EditText1.Initialize("EditText1")
' EditText1.ForceDoneButton = True
Page1.RootPanel.AddView(EditText1, 10dip, 10dip, 300dip, 60dip)
End Sub

'Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
Sub socket1_connected (Successful As Boolean)
If Successful Then
hd.ToastMessageShow("Connected", False)
'Can only use prefix mode if both sides of the connection implement the prefix protocol!!!
AStreams.Initialize(socket1.InputStream,socket1.OutputStream, "AStreams")
Else
hd.ToastMessageShow(LastException.Message, True)
End If
Server.Listen
End Sub

Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
hd.ToastMessageShow("Connected", False)
socket1 = NewSocket
'Can only use prefix mode if both sides of the connection implement the prefix protocol!!!
AStreams.Initialize(socket1.InputStream,socket1.OutputStream, "AStreams")
Else
hd.ToastMessageShow(LastException.Message, True)
End If
Server.Listen
End Sub

Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
hd.ToastMessageShow(msg, True)
Log(msg)
End Sub

Sub AStreams_Error
hd.ToastMessageShow(LastException.Message, True)
Log("AStreams_Error")
End Sub

Sub AStreams_Terminated
Log("AStreams_Terminated")
End Sub

'press on the Done button to send text
Sub EditText1_EnterPressed
If AStreams.IsInitialized = False Then Return
If EditText1.Text.Length > 0 Then
Dim buffer() As Byte
buffer = EditText1.Text.GetBytes("UTF8")
AStreams.Write(buffer)
EditText1.SelectAll
Log("Sending: " & EditText1.Text)
End If
End Sub

Sub Activity_Pause(UserClosed As Boolean)
If UserClosed Then
Log("closing")
AStreams.Close
socket1.Close
End If
End Sub
 
Upvote 0
Top