Hi
I have done an App which uses a SocketServer object. It's purpose is to "Receive/Send" Ascii strings from/to a Client, and "Send" Camera pictures to it. For this task I "composed" the App using AsyncStreamsText, AsyncStreamsObject and CameraEx sources.
Despite the program works, I have some questions on this subject, to be sure of what I did:
1) I used both AsyncStreamsText (for Ascii strings I/O) and AsyncStreamsObject (for picture Output) because it seems to me that the second doesn't support sending/receivin Ascii strings.
2) The only way to send a Camera taken picture is to capture it, write it on a file and send this file.
3) I am using the NewSocket socket of the following code, to initialize both AsyncStreams objects. Is it correct?
4) Monitoring the client, which is a C++ program, I see that the picture arrives in parts: first 4 bytes, then 54, then again 4 and finally various blocks of 1460 bytes (and a last one different). Does this subdivision mean anything or I must simply recompose the file on arrival?
Hope that my doubts are useful for other people too. Thanks for attention.
I have done an App which uses a SocketServer object. It's purpose is to "Receive/Send" Ascii strings from/to a Client, and "Send" Camera pictures to it. For this task I "composed" the App using AsyncStreamsText, AsyncStreamsObject and CameraEx sources.
Despite the program works, I have some questions on this subject, to be sure of what I did:
1) I used both AsyncStreamsText (for Ascii strings I/O) and AsyncStreamsObject (for picture Output) because it seems to me that the second doesn't support sending/receivin Ascii strings.
2) The only way to send a Camera taken picture is to capture it, write it on a file and send this file.
3) I am using the NewSocket socket of the following code, to initialize both AsyncStreams objects. Is it correct?
B4X:
Sub Process_Globals ' code is inside a service
Private RemoteCaller As AsyncStreamsText
Private SendPhoto As AsyncStreamsObject
Dim ServerS As ServerSocket
Dim nPort As Int : nPort=10250
End Sub
Sub Service_Create
ServerS.Initialize(nPort,"ServerEvents")
End Sub
Sub Service_Start (StartingIntent As Intent)
MyIp=ServerS.GetMyIP
ServerS.Listen
End Sub
Sub ServerEvents_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
RemoteCaller.Initialize(Me, "Server",NewSocket.InputStream,NewSocket.OutputStream) ' strings I/O
SendPhoto.Initialize(Me,"Image") ' for sending picture
SendPhoto.Start(NewSocket.InputStream,NewSocket.OutputStream)
Else
Msgbox(LastException.Message, "Error connecting")
End If
'ServerS.Listen ' don't need continue listening to new incoming connections
End Sub
Hope that my doubts are useful for other people too. Thanks for attention.