📄 frmmain.class
字号:
' Gambas class filePRIVATE Client AS Object[]PRIVATE Waiting AS BooleanPUBLIC SUB Button1_Click() IF combobox2.Index=0 THEN 'TCP Server.Type=Net.Internet ' The port to listen to Server.Port=Val(TextBox1.Text) ' we start listening Server.Listen(ComboBox1.Index) ELSE ' UNIX Server.Type=Net.Local ' You could also use Net.Unix Server.Path=TxtPath.Text Server.Listen(ComboBox1.Index) END IF IF Server.Status=Net.Active THEN ' listening Button1.Enabled=FALSE button2.Enabled=TRUE ComboBox1.Enabled=FALSE ComboBox2.Enabled=FALSE TxtPath.Enabled=FALSE END IF ENDPUBLIC SUB Server_Error() Message.Error("Unable to bind socket") ENDPUBLIC SUB Server_Connection(sHost AS String) '******************************* ' A client has arrived! ' let's accept it DIM Obj AS Object IF Server.Status<=Net.Inactive THEN RETURN IF ComboBox2.Index=0 THEN TextArea1.Text=TextArea1.Text & "Connection request from : " & sHost & Chr(13) & Chr(10) ELSE TextArea1.Text=TextArea1.Text & "Connection request accepted" & Chr(13) & Chr(10) END IF Obj=Server.Accept() Client.Add(Obj) IF Obj.Status=Net.Connected AND ComboBox2.Index=0 THEN TextArea1.Text=TextArea1.Text & "Connection from " & Obj.RemoteHost & ":" & Obj.RemotePort & " accepted (local port " & Obj.LocalPort & ")" & Chr(13) & Chr(10) END IF ENDPUBLIC SUB Socket_Read() DIM sBuf AS String '****************************** ' When some data arrives to ' our server, we respond with ' an echo '***************************** IF LAST.Status <> Net.Connected THEN RETURN READ #LAST,sBuf,Lof(LAST) TextArea1.Text=TextArea1.Text & "Socket number " & Client.Find(LAST) & " --> " & sBuf WRITE #LAST,sBuf,Len(sBuf) ENDPUBLIC SUB Socket_Ready() TextArea1.Text=TextArea1.Text & "-- Client working --" & Chr(13) & Chr(10) ENDPUBLIC SUB Socket_Closed() TextArea1.Text=TextArea1.Text & "Client " & Client.Find(LAST) & " Closed" Client.Remove (Client.Find(LAST)) ENDPUBLIC SUB Form_Open() Client=NEW Object[] TxtPath.Text=Application.Path & "/" & "gambas" TxtPath.Enabled=FALSE TextLabel3.Text="Path (Max." & ServerSocket.MaxPathLength & ")"ENDPUBLIC SUB Button2_Click() Server.Close() Button2.Enabled=FALSE button1.Enabled=TRUE ComboBox1.Enabled=TRUE ComboBox2.Enabled=TRUE ComboBox2_Click()ENDPUBLIC SUB Form_Close() ' We have to be sure of closing the server before exiting Server.Close()ENDPUBLIC SUB CmdWait_Click() IF Waiting THEN Server.Resume() CmdWait.Text="Pause" ELSE Server.Pause() CmdWait.Text="Resume" END IF Waiting=NOT WaitingENDPUBLIC SUB ComboBox2_Click() IF ComboBox2.Index=0 THEN TextBox1.Enabled=TRUE TxtPath.Enabled=FALSE ELSE TextBox1.Enabled=FALSE TxtPath.Enabled=TRUE END IFEND
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -