hi
ich hab schon mindestens 3 mal versucht einen Server mit UDP zu proggen - funst aba immer noch nicht...
es laggt IMMER
Hat das ÜBERHAUPT schon mal jemand geschafft zu proggen???
wenn nicht, würde ich nicht DP, nicht UDP, sondern ne ganz andere sprache nehmen............
(ich hoffe trotzdem jemand weiß rat...)
hier der code:
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] fen = CreateWindow (\"Detected Server\",0,0,340,350,0,1)
Global console = CreateTextArea (10,10,200,275,fen,1) eingabe = CreateTextField (10,290,200,20,fen) : SetGadgetText eingabe,\"/start\" player = CreateListBox (220,10,100,300,fen)
port = 3578
AddTextAreaText console,Chr$(13)
Type play Field ip Field x,y,winkel Field name$ Field pong Field ping Field port End Type
Repeat Select WaitEvent(1) Case $401 If EventSource() = Eingabe And EventData() = 13 Then eingabetext$ = TextFieldText(eingabe) Select Left$(eingabetext$,6) Case \"/chelp\" ctext(\"/cport \") Case \"/cport\" porteingabe = Int (Right$(eingabetext$,Len(eingabetext$)-7)) If porteingabe <= 65535 And porteingabe => 0 teststream = CreateUDPStream () If teststream <> 0 Then port = porteingabe ctext(\"Der Port \"+port+\" wird jetzt verwendet\") Else ctext(\"Der Port \" + porteingabe + \" wird bereits verwendet oder ist ungültig\") EndIf CloseUDPStream teststream Else ctext(\"Der Port \" + porteingabe + \" ist ungültig\") EndIf Case \"/start\" open = 1 sendstream = CreateUDPStream () empfstream = CreateUDPStream (port) If sendstream = 0 Or empfstream = 0 Then End ctext(\"Server gestartet\") Case \"/close\" open = 0 CloseUDPStream sendstream CloseUDPStream empfstream ctext(\"Server geschlossen\") Default ctext (eingabetext$) End Select SetGadgetText eingabe,\"\" EndIf Case $803 End End Select ActivateGadget eingabe If open = 1 Then ipnummer = RecvUDPMsg (empfstream) If ipnummer <> 0 Then Select ReadByte (empfstream) Case 1 For spieler.play = Each play If ipnummer = spieler\ip Then ctext(spieler\name$+\" ist gegangen\") Delete spieler.play EndIf Next ClearGadgetItems player For spieler = Each play AddGadgetItem player,spieler\name$+\" :\"+spieler\port Next Case 2 ex = ReadShort(empfstream) ey = ReadShort(empfstream) ewinkel = ReadShort(empfstream) ename$ = ReadLine(empfstream) newplayer = 1 For spieler.play = Each play If ipnummer = spieler\ip Then spieler\x = ex spieler\y = ey spieler\winkel = ewinkel spieler\name$ = ename$ spieler\ping = MilliSecs() - spieler\pong newplayer = 0 EndIf Next If newplayer = 1 Then spieler.play = New play spieler\ip = ipnummer spieler\port = UDPMsgPort (empfstream) ctext(ename$+\" ist begetreten\") ClearGadgetItems player For spieler = Each play AddGadgetItem player,spieler\name$+\" :\"+spieler\port Next EndIf End Select EndIf a = 0 For spieler.play = Each play a = a + 1 Next For spieler.play = Each play WriteByte sendstream,2 WriteByte sendstream,a For dat.play = Each play WriteLine sendstream,Str$(dat\ip) WriteShort sendstream,dat\x WriteShort sendstream,dat\y WriteShort sendstream,dat\winkel WriteLine sendstream,dat\name$ Next SendUDPMsg sendstream,spieler\ip,spieler\port Next For spieler.play = Each play WriteByte sendstream,1 SendUDPMsg sendstream,spieler\ip,spieler\port spieler\pong = MilliSecs() Next EndIf If timeout < MilliSecs() For spieler.play = Each play WriteByte sendstream,1 SendUDPMsg sendstream,spieler\ip,spieler\port spieler\pong = MilliSecs() Next timeout = MilliSecs() + 1000 Else timeout = MilliSecs() + 1000 EndIf ClearGadgetItems player For spieler = Each play AddGadgetItem player,spieler\name$+\" :\"+spieler\port+\" :\"+spieler\ping Next
Forever
Function ctext(eingabetext$) AddTextAreaText console,eingabetext$ + Chr$(13) End Function
und von Clienten:
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] fen = CreateWindow (\"sender\",0,0,600,550,0,1)
graph = CreateCanvas (10,10,500,500,fen)
stream = CreateUDPStream () If stream = 0 Then RuntimeError(\"Fehler: 001\")
CountHostIPs(\"\") eigenip = HostIP(1) winkel = 1 name$ = \"Nickname\" ip = int_ip(\"127.0.0.1\") port = 3578 get = 0
Type play Field ip Field x,y,winkel Field name$ End Type
Repeat Select WaitEvent(1) Case $101 Select EventData() Case 200 y = y -5 Case 208 y = y +5 Case 203 x = x -5 Case 205 x = x +5 Case 57 winkel = winkel + 1 End Select Case $803 WriteByte stream,1 SendUDPMsg stream,ip,port End End Select SetBuffer CanvasBuffer(graph) Cls Color 255,255,255 Rect x,y,10,10,1 For spieler.play = Each play Rect spieler\x,spieler\y,10,10,1 Next Text x,y+10,winkel+\":\"+zahl Text x+10,y,send FlipCanvas graph If send = 1 Or get = 0 Then WriteByte stream,2 WriteShort stream,x WriteShort stream,y WriteShort stream,winkel WriteLine stream,name$ SendUDPMsg stream,ip,port send = 0 EndIf If RecvUDPMsg (stream) <> 0 Then Select ReadByte(stream) Case 1 send = 1 Case 2 For Var = 1 To ReadByte(stream) ipnummer = Int (ReadLine$(stream)) ex = ReadShort(stream) ey = ReadShort(stream) ewinkel = ReadShort(stream) ename$ = ReadLine(stream) newplayer = 1 empfip = UDPMsgIP(stream) For spieler.play = Each play If empfip = spieler\ip Then spieler\x = ex spieler\y = ey spieler\winkel = ewinkel spieler\name$ = ename$ newplayer = 0 ElseIf empfip = eigenip newplayer = 0 EndIf Next If newplayer = 1 Then spieler.play = New play spieler\ip = empfip spieler\x = ex spieler\y = ey spieler\winkel = ewinkel spieler\name$ = ename$ EndIf Next End Select get = 1 EndIf Forever
Function INT_IP(IP$) a1=Int(Left(IP$,Instr(IP$,\".\")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,\".\")) a2=Int(Left(IP$,Instr(IP$,\".\")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,\".\")) a3=Int(Left(IP$,Instr(IP$,\".\")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,\".\")) a4=Int(IP$) Return (a1 Shl 24) + (a2 Shl 16) + (a3 Shl 8 ) +a4 End Function
|