B4J socket service interruption,event trigger?? AStreams_Error or AStreams_Terminated,
but B4J doesn't...
Same experiment, I'm sure B4A has,it will execute the event (AStreams_Terminated,)
Maybe I is wrong. But I checked..
B4A and B4J are using the same code... so I can only help
B4J V9.3
JNetwork V1.2
jRandomAccessFile V2.34
B4A V11.2
Network V1.52
RandomAccessFile V2.33
but B4J doesn't...
Same experiment, I'm sure B4A has,it will execute the event (AStreams_Terminated,)
Maybe I is wrong. But I checked..
B4A and B4J are using the same code... so I can only help
B4J V9.3
JNetwork V1.2
jRandomAccessFile V2.34
B4A V11.2
Network V1.52
RandomAccessFile V2.33
B4J socket:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
Private server As ServerSocket
Private client As Socket
Private astream As AsyncStreams
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
'服務器 初始化.並寫聆聽.....如果是單純的client,可以不加入server功能
server.Initialize(51042, "server")
'GetMyIP=server.GetMyIP
Try
server.Listen
Catch
'WifiStatus = "Error listening: " & LastException
Log("server 出錯了???"& LastException)
End Try
End Sub
Sub Button1_Click
'xui.MsgboxAsync("Hello World!", "B4X")
client.Initialize("client")
client.Connect("192.168.1.180",51042,50000)
End Sub
'server accepted client
Private Sub server_NewConnection (Successful As Boolean, NewSocket As Socket)
Log("server_NewConnection==>")
If Successful Then
client = NewSocket
astream.InitializePrefix( client.InputStream, False, client.OutputStream, "astreams")
Log("socket1_Connected ok")
Else
Log("server_NewConnection連線失敗: " & LastException)
End If
server.Listen '處裡完使用者的連線.要啟動聆聽
End Sub
Sub client_connected(Successful As Boolean)
Log("socket1_Connected==>")
If Successful Then
astream.InitializePrefix(client.InputStream, False, client.OutputStream, "astreams")
Log("socket1_Connected ok")
Else
Log("socket1_Connected fail: " & LastException)
End If
End Sub
Sub AStreams_Error
'ToastMessageShow(LastException.Message, True)
Log("AStreams_Error")
End Sub
Sub AStreams_Terminated
Log("AStreams_Terminated中斷了")
End Sub
B4A socket:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#BridgeLogger: True
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#BridgeLogger: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Private server As ServerSocket
Private client As Socket
Private astream As AsyncStreams
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
'服務器 初始化.並寫聆聽.....如果是單純的client,可以不加入server功能
server.Initialize(51042, "server")
'GetMyIP=server.GetMyIP
Try
server.Listen
Catch
'WifiStatus = "Error listening: " & LastException
Log("server 出錯了???"& LastException)
End Try
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
'xui.MsgboxAsync("Hello world!", "B4X")
client.Initialize("client")
client.Connect("192.168.1.162",51042,50000)
End Sub
'server accepted client
Private Sub server_NewConnection (Successful As Boolean, NewSocket As Socket)
Log("server_NewConnection==>")
If Successful Then
client = NewSocket
astream.InitializePrefix( client.InputStream, False, client.OutputStream, "astreams")
Log("socket1_Connected ok")
Else
Log("server_NewConnection連線失敗: " & LastException)
End If
server.Listen '處裡完使用者的連線.要啟動聆聽
End Sub
Sub client_connected(Successful As Boolean)
Log("socket1_Connected==>")
If Successful Then
astream.InitializePrefix(client.InputStream, False, client.OutputStream, "astreams")
Log("socket1_Connected ok")
Else
Log("socket1_Connected fail: " & LastException)
End If
End Sub
'錯誤時 觸發
Sub astreams_Error
Log("Astream_Error==>")
Log("Error: " & LastException)
'astream.Close
End Sub
'連線中斷時 觸發
Sub astreams_Terminated
Log("Astream_Terminated==>")
'astream.Close
End Sub
Attachments
Last edited: