Verfasst: 17.02.2006 00:10
Und was soll mir der Code bringen?
KeyKon
KeyKon
Code: Alles auswählen
;-Config
Port = 335
If CreateNetworkServer(Port)
;-Main Loop
Repeat
Delay(1)
Buffer.s = ""
deltEvent.l = NetworkServerEvent()
If deltEvent
ClientID = NetworkClientID()
Select deltEvent
Case 1
SendNetworkData(ClientID, "Connecting..."+Chr(13)+Chr(0), 2000)
Case 2
;ReceiveNetworkData(ClientID, Buffer.s, 2000)
buffer.s=Space(2000)
ReceiveNetworkData(NetworkClientID(),@buffer,2000)
buffer.s = RTrim(buffer.s)
Delay(10)
MessageRequester("MELDUNG VOM SERVER", buffer.s, 0)
Case 4
Buffer.s = ""
EndSelect
EndIf
ForEver
Else
MessageRequester("SYSTEM", "ERRO", 0)
EndIf
Code: Alles auswählen
; Author: kaitec
; Date: xx.xx.xxxx
; OS: Windows
; ++++++++++++++++++++++++ Network Client Example +++++++++++++++++++++++++++++++
#Win = 0
;-0OpenWindow
OpenWindow(#Win, 0, 0, 105, 300, #PB_Window_SystemMenu|#PB_Window_Screencentered|#PB_Window_MinimizeGadget, "Net")
hBrush.l = CreateSolidBrush_(RGB(30,50,80))
SetClassLong_(WindowID(0), #GCL_HBRBACKGROUND, hBrush.l)
InvalidateRect_(WindowID(0), #Null, #True)
If CreateGadgetList(WindowID())
ButtonGadget(1, 10, 5,100,20,"Befehl SENDEN")
EndIf
Repeat
If WindowEvent() = #PB_EventCloseWindow
End
EndIf
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 111
EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
DeleteObject_(hBrush.l)
End
Code: Alles auswählen
; Autor: freak
; Datum: ?
; Forum: ?
; PB 3.93
; ++++++++++++++++++++++++ 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
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Code: Alles auswählen
; Autor: freak
; Datum: ?
; Forum: ?
;PB 3.93
; ++++++++++++++++++++++++ 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) ;127.0.0.1 = Localhost
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)
; Main Loop
MessageRequester("", Str(ConnID))
Repeat
If WaitWindowEvent() = #PB_EventCloseWindow
End
EndIf
If NetworkClientEvent(ConnID) = 2
text.s = Space(500)
ReceiveNetworkData(ConnID, @text, 500)
AddGadgetItem(1,-1,text)
EndIf
ForEver
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++