1. Hatte schon mal irgendwann im Code Archiv etwas gefunden.
Habe das Beispiel etwas geändert und die Message 2000 für FD_CLOSE verwendet.
2. TCP/IP ist schon eine Sicherungsschicht. Wozu noch einmal CRC prüfen wenn diese schon im TCP geprüft wird.
Sollte mal das Packet nicht sauber ankommen, wird es automatisch wiederholt.
Code: Alles auswählen
; English forum:
; Author: freak
; Date: 21. January 2003
; OS: Windows
; Demo: No
; ++++++++++++++++++++++++ Network Client Example +++++++++++++++++++++++++++++++
OpenWindow(0, 0, 0, 300, 400, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "Network Client")
CreateGadgetList(WindowID())
ListViewGadget(1, 5, 5, 290, 390)
If InitNetwork()=0: End: EndIf ; Initialize Network Stuff
ConnID.l = OpenNetworkConnection("127.0.0.1",6000)
If ConnID = 0: End: EndIf
; The following call will activate this Trick
;
; ConnID : connection ID (from OpenNetworkConnection)
; WindowID() : ID of a Window, to send the Events to.
; #WM_NULL : The Message to be Send, if a Network Event occurs.
; #WM_NULL will be ignored, but still causes the WaitWindowEvent() to return,
; and then the NetworkEvent to be called.
; #FD_ALL : Event to be send to Callback Procedure, we request them all.
#FD_ALL = #FD_READ|#FD_WRITE|#FD_OOB|#FD_ACCEPT|#FD_CONNECT|#FD_CLOSE
WSAAsyncSelect_(ConnID, WindowID(), #WM_NULL, #FD_ALL)
WSAAsyncSelect_(ConnID, WindowID(), 2000, #FD_CLOSE)
; Main Loop
Repeat
r1 = WaitWindowEvent()
If r1 = #PB_EventCloseWindow Or r1 = 2000
End
EndIf
If NetworkClientEvent(ConnID) = 2
Text.s = Space(500)
ReceiveNetworkData(ConnID, @Text, 500)
AddGadgetItem(1,-1,Text)
EndIf
ForEver
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; ExecutableFormat=Windows
; FirstLine=1
; EOF
Code: Alles auswählen
; English forum:
; Author: freak
; Date: 21. January 2003
; OS: Windows
; Demo: No
; ++++++++++++++++++++++++ Network Server Example +++++++++++++++++++++++++++++++
OpenWindow(0,0,0,300,80, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "Network Server")
;von freak
; ++++++++++++++++++++++++ Network Server Example +++++++++++++++++++++++++++++++
CreateGadgetList(WindowID())
StringGadget(0, 5, 5, 290, 25, "")
ButtonGadget(1, 5, 40, 80, 25, "Send")
DisableGadget(1,1)
If InitNetwork() = 0: End: EndIf ; Initialize Network Stuff
SOCKET.l = CreateNetworkServer(6000)
If SOCKET = 0: End: EndIf
; The following call will activate this Trick
;
; SOCKET : SOCKET (or Connection ID) is returned by CreateNetworkServer()
; WindowID() : ID of a Window, to send the Events to.
; #WM_NULL : The Message to be Send, if a Network Event occurs.
; #WM_NULL will be ignored, but still causes the WaitWindowEvent() to return,
; and then the NetworkEvent to be called.
; #FD_ALL : Event to be send to Callback Procedure, we request them all.
#FD_ALL = #FD_READ|#FD_WRITE|#FD_OOB|#FD_ACCEPT|#FD_CONNECT|#FD_CLOSE
WSAAsyncSelect_(SOCKET, WindowID(), #WM_NULL, #FD_ALL)
;Main Loop
Repeat
Select WaitWindowEvent()
Case #PB_EventCloseWindow
End
Case #PB_EventGadget
If EventGadgetID() = 1
text.s = GetGadgetText(0)
SendNetworkData(NetworkClientID(), @text, Len(text)+1)
EndIf
EndSelect
Select NetworkServerEvent()
Case 1
DisableGadget(1,0) ; user connected, enable sending.
Case 4
DisableGadget(1,1) ; user disconnected, disable sending.
EndSelect
ForEver
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; ExecutableFormat=Windows
; FirstLine=1
; EOF
