UDP Packet wird in if abfrage nicht gesendet
Übersicht

![]() |
InFaINBetreff: UDP Packet wird in if abfrage nicht gesendet |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi,
Ich bin gerade dabei mich einmal wieder in BlitzBasic einzuarbeiten... Nun bin ich daran einen einfachen Chat zum wiedereinstieg zu Programieren. Wie ihr seht sind im Client Code 2 sendMsg auskommentiert. Wenn ich das kommentar entferne dann werden diese sendMsg erfolgreich ausgeführt.... Aber ein enter bewirkt nur ein hochzählen der gesendeten Packete. Versteht ihr was ich meine? Ich hoffe mir kann jemand helfen. Hier der Code: Client: Code: [AUSKLAPPEN] AppTitle("Client")
Global mh Global gui_selinp Type msgs Field Clr$ Field msg$ End Type Global msgt.msgs Global out,in Global timer = CreateTimer(25) Global y = -16 Global msg_all = 0 Global udp_stream = CreateUDPStream(1338) If(udp_stream = 0)Then End EndIf add_msg("Client erfolgreich gestartet") msgt.msgs = New msgs msgt\clr$ = "white" msgt\msg$ = msg$ Global ip = integer_ip("127.0.0.1") sendMsg("join") SetBuffer BackBuffer() Repeat mh = 0 If MouseHit(1) Then mh = 1 text1$ = gui_input$(1,280,text1$,1) ip = RecvUDPMsg(udp_stream) If(ip <> 0)Then in = in + 1 msg$ = DottedIP(ip) msg$ = msg$ + ": " msg$ = msg$ + ReadLine(udp_stream) add_msg(msg$) ;sendMsg("HI") EndIf WaitTimer timer S$ = out S$ = S$ + "/" S$ = S$ + in add_msg(S$) ;sendMsg(S$) If(KeyHit(28))Then send = 1 sendMsg(text1$) text1$ = "" EndIf print_all(msg_all-15,msg_all+1) Flip Cls Forever Function gui_input$(x,y,txt$,id) Color 255,255,255 Rect x-1,y-1,StringWidth(txt$)+15,StringHeight(txt)+2,0 If mh If RectsOverlap(x,y,StringWidth(txt)+16,StringHeight(txt),MouseX(),MouseY(),1,1) And gui_erra = 0 gui_selinp = id ElseIf gui_selinp = id gui_selinp = -1 EndIf EndIf If id=gui_selinp Then key=GetKey() If key>31 Then txt$=txt$+Chr(key) If KeyHit(82) Then txt$=txt$+"0" If KeyHit(79) Then txt$=txt$+"1" If KeyHit(80) Then txt$=txt$+"2" If KeyHit(81) Then txt$=txt$+"3" If KeyHit(75) Then txt$=txt$+"4" If KeyHit(76) Then txt$=txt$+"5" If KeyHit(77) Then txt$=txt$+"6" If KeyHit(71) Then txt$=txt$+"7" If KeyHit(72) Then txt$=txt$+"8" If KeyHit(73) Then txt$=txt$+"9" If KeyHit(181) Then txt$=Left(txt$,Len(txt$)-1):txt$=txt$+"/" If KeyHit(83) Then txt$=txt$+"," If KeyHit(14) And Len(txt$)>0 Then txt$=Left(txt$,Len(txt$)-1) Rect x+StringWidth(txt$)+4,y+11,5,1 EndIf Text x+3,y,txt$ Return txt$ End Function Function sendMsg(msg$) WriteLine(udp_stream, msg$) SendUDPMsg udp_stream, ip, 1337 out = out + 1 End Function Function add_line(msg$) y = y + 16 If(y > 288)Then Cls y = 0 EndIf Text 0,y,msg End Function Function add_msg(msg$) msgt = New msgs msgt\clr$ = "white" msgt\msg$ = msg$ msg_all = msg_all+1 End Function Function print_all(start, sto) y=0 i = 0 start = start - 1 For msgt=Each msgs If(i >start)Then If(i<sto)Then add_line(msgt\msg) EndIf EndIf i = i + 1 Next End Function Function getText(msg$) y = y + 16 If(y > 288)Then Cls y = 0 EndIf Locate 0,y re$ = Input(msg$) Return re$ End Function Function integer_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 Server: Code: [AUSKLAPPEN] AppTitle("Server")
Global timer = CreateTimer(1000) Global y = -16 Dim player(10) Global udp_stream = CreateUDPStream(1337) If(udp_stream = 0)Then End EndIf add_line("Server erfolgreich gestartet") Repeat ip = RecvUDPMsg(udp_stream) If(ip <> 0)Then msg$ = DottedIP(ip) msg$ = msg$ + ": " msg$ = msg$ + ReadLine(udp_stream) add_line(msg$) If(Instr(msg$,"join"))Then i = getFree() player(i) = ip sendMsg("New Player joined!") Else sendMsg(msg$) EndIf EndIf WaitTimer(timer) Forever Function sendMsg(msg$) For n = 0 To 10 If(player(n) <> 0)Then WriteLine(udp_stream, msg$) SendUDPMsg udp_stream, player(n), 1338 EndIf Next End Function Function getFree() For n = 0 To 10 If(player(n) = 0)Then Return n EndIf Next End Function Function add_line(msg$) y = y + 16 If(y > 288)Then Cls y = 0 EndIf Text 0,y,msg End Function Vielen Dank InFaIN |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group