Need help on the LAN Network Data Transmitting.. Too much Delay(ping)..
Author |
Message |
8749236
|
Posted: Wed Jun 01, 2011 4:21 pm Post subject: Need help on the LAN Network Data Transmitting.. Too much Delay(ping).. |
|
|
What is it you are trying to achieve?
I wrote a game with LAN, and i tried to play on LAN, it works well but the delay(ping) is really high...
So i'm trying to lower it down..
PS: LAN = Local Area Network
What is the problem you are having?
The Delay(ping) of LAN is too high..
By the way i'm running 2 games on 1 computer for testing LAN, is that the cause of this problem???
Describe what you have tried to solve this problem
I tried to reduce the size of data i'm sending, i used tons of "get" and "put" command when i'm trying to sent datas through LAN, but after i reduce it(reduced to 6) theres no effect..
The delay is still same, 2 seconds plus.. delay..
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
procedure LANConnecting (var input : int)
% set View so it can display normally..
View.Set ("nooffscreenonly,nocursor")
% Run a server!!!
if input = 2 then
Draw.Text ("Your IP: " + serverAddress, cx - 180, cy + 68, smallFont, brightred)
Draw.Text ("Server is running.. Waiting for Connections..", cx - 180, cy + 50, smallFont, brightred)
View.Update
serverAddress := Net.LocalAddress
DataTransfer := Net.WaitForConnection (serverPort, serverAddress )
cls
% get player name
Draw.Text ("Please enter your player name, 10 Letters MAXIMUM!!",
cx - 180, cy + 50, smallFont, brightred)
Draw.Text ("Enter Here: ", cx - 180, cy + 32, smallFont, brightred)
locate (17, 39)
get playerName (1)
Input.Flush % prevent too much input..
cls
% sent your name..
SR (1).playerName := playerName (1)
put : DataTransfer, SR (1).playerName
% switch the player name first..
loop
% check is there data transmitting..
if Net.LineAvailable (DataTransfer ) then
get : DataTransfer, SR (2).playerName
playerName (2) := SR (2).playerName
connected := true
end if
% exit if theres datas returned..
exit when connected
end loop
elsif input = 3 then % connect to a server
% get the address
Draw.Text ("Your IP: " + serverAddress, cx - 180, cy + 68, smallFont, brightred)
Draw.Text ("Please enter the Server Address to connect to..", cx - 180, cy + 50, smallFont, brightred)
Draw.Text ("Enter here:", cx - 180, cy + 32, smallFont, brightred)
locate (17, 39)
get serverAddress
cls
Draw.Text ("Attempting to connect to " + Net.HostNameFromAddress (serverAddress ), cx - 180, cy + 50, menuFont, brightred)
% get the first data..
DataTransfer := Net.OpenConnection (serverAddress, serverPort )
% check the connection, failed or not..
if DataTransfer <= 0 then
Draw.Text ("Unable to connect to " + serverAddress, cx - 180, cy + 32, smallFont, brightred)
confirmedS := false % return to menu
connected := false
else
cls
% get player name
Draw.Text ("Please enter your player name, 10 Letters MAXIMUM!!",
cx - 180, cy + 50, smallFont, brightred)
Draw.Text ("Enter Here: ", cx - 180, cy + 32, smallFont, brightred)
locate (17, 39)
get playerName (1)
Input.Flush % prevent too much input..
cls
% sent your name..
SR (1).playerName := playerName (1)
put : DataTransfer, SR (1).playerName
Draw.Text ("Game will start after the Game got response..", cx - 180, cy + 50, smallFont, brightred)
% switch the player name first..
loop
% check is there data transmitting..
if Net.LineAvailable (DataTransfer ) then
get : DataTransfer, SR (2).playerName
playerName (2) := SR (2).playerName
connected := true
end if
% exit if theres datas returned..
exit when connected
end loop
end if
delay (3000)
end if
% restore the View.Set when finished..
View.Set ("offscreenonly")
end LANConnecting
procedure LANRead (var connectedToTarget : boolean)
if connectedToTarget then
% ********************************
% *** get ready to transfer ***
% ********************************
% players
SR (1).px := intstr (p (1).px )
SR (1).py := intstr (p (1).py )
SR (1).spd := realstr (p (1).spd, 2)
SR (1).shells := intstr (p (1).shells )
SR (1).missiles := intstr (p (1).missiles )
SR (1).flares := intstr (p (1).flares )
SR (1).DP := intstr (p (1).DP )
SR (1).a := intstr (a (1))
% shells
SR (1).n := intstr (n (1))
for i : 1 .. n (1)
SR (1).Bx (i ) := intstr (fire1 (i ).Bx )
SR (1).By (i ) := intstr (fire1 (i ).By )
%SR (1).bmx (i) := fire1 (i).bmx
%SR (1).bmy (i) := fire1 (i).bmy
end for
% missiles
if m (1).maw then
SR (1).maw := "1"
else
SR (1).maw := "0"
end if
SR (1).mx := intstr (m (1).mx )
SR (1).my := intstr (m (1).my )
SR (1).d := realstr (m (1).d, 2)
%SR (1).ma := m (1).ma
SR (1).ps := intstr (m (1).ps )
SR (1).mttl := intstr (m (1).ttl )
% flares
SR (1).f := intstr (f (1))
if f1 (0).fw then
SR (1).fw := "1"
else
SR (1).fw := "0"
end if
for i : 1 .. f (1)
% flares
SR (1).fx (i ) := intstr (f1 (1).fx )
SR (1).fy (i ) := intstr (f1 (1).fy )
%SR (1).fmx (i) := f1 (1).fmx
%SR (1).fmy (i) := f1 (1).fmy
end for
% ****************************
% *** Transfering Datas ***
% ****************************
% sent datas
% player
put : DataTransfer, SR (1).px
put : DataTransfer, SR (1).py
put : DataTransfer, SR (1).spd
put : DataTransfer, SR (1).shells
put : DataTransfer, SR (1).missiles
put : DataTransfer, SR (1).flares
put : DataTransfer, SR (1).DP
put : DataTransfer, SR (1).a
% shells
put : DataTransfer, SR (1).n
for i : 1 .. strint (SR (1).n )
put : DataTransfer, SR (1).Bx (i )
put : DataTransfer, SR (1).By (i )
%put : DataTransfer, SR (1).bmx (i)
%put : DataTransfer, SR (1).bmy (i)
end for
% missiles
put : DataTransfer, SR (1).maw
put : DataTransfer, SR (1).mx
put : DataTransfer, SR (1).my
put : DataTransfer, SR (1).d
%put : DataTransfer, SR (1).ma
put : DataTransfer, SR (1).ps
put : DataTransfer, SR (1).mttl
% flares
put : DataTransfer, SR (1).f
put : DataTransfer, SR (1).fw
for i : 1 .. strint (SR (1).f )
put : DataTransfer, SR (1).fx (i )
put : DataTransfer, SR (1).fy (i )
%put : DataTransfer, SR (1).fmx (i)
%put : DataTransfer, SR (1).fmy (i)
end for
% *****************************
% *** Get Datas from LAN ***
% *****************************
% get datas if they are incoming..
if Net.LineAvailable (DataTransfer ) then
% player
get : DataTransfer, SR (2).px : *
get : DataTransfer, SR (2).py : *
get : DataTransfer, SR (2).spd : *
get : DataTransfer, SR (2).shells : *
get : DataTransfer, SR (2).missiles : *
get : DataTransfer, SR (2).flares : *
get : DataTransfer, SR (2).DP : *
get : DataTransfer, SR (2).a : *
% shells
get : DataTransfer, SR (2).n : *
for i : 1 .. strint (SR (2).n )
get : DataTransfer, SR (2).Bx (i ) : *
get : DataTransfer, SR (2).By (i ) : *
%get : DataTransfer, SR (2).bmx (i)
%get : DataTransfer, SR (2).bmy (i)
end for
% missiles
get : DataTransfer, SR (1).maw : *
get : DataTransfer, SR (2).mx : *
get : DataTransfer, SR (2).my : *
get : DataTransfer, SR (2).d : *
%get : DataTransfer, SR (2).ma
get : DataTransfer, SR (2).ps : *
get : DataTransfer, SR (2).mttl : *
% flares
get : DataTransfer, SR (2).f : *
get : DataTransfer, SR (2).fw : *
for i : 1 .. strint (SR (2).f )
get : DataTransfer, SR (2).fx (i ) : *
get : DataTransfer, SR (2).fy (i ) : *
%get : DataTransfer, SR (2).fmx (i)
%get : DataTransfer, SR (2).fmy (i)
end for
% sent the data into correct variables..
% *** MUST IN ORDER ***
% player
p (2).px := strint (SR (2).px )
p (2).py := strint (SR (2).py )
p (2).spd := strreal (SR (2).spd )
p (2).shells := strint (SR (2).shells )
p (2).missiles := strint (SR (2).missiles )
p (2).flares := strint (SR (2).flares )
p (2).DP := strint (SR (2).DP )
a (2) := strint (SR (2).a )
% shells
n (2) := strint (SR (2).n )
for i : 1 .. n (2)
fire2 (i ).Bx := strint (SR (2).Bx (i ))
fire2 (i ).By := strint (SR (2).By (i ))
%fire2 (i).bmx := SR (2).bmx (i)
%fire2 (i).bmy := SR (2).bmy (i)
end for
% missiles
if SR (1).maw = "1" then
m (2).maw := true
else
m (2).maw := false
end if
m (2).mx := strint (SR (2).mx )
m (2).my := strint (SR (2).my )
m (2).d := strreal (SR (2).d )
%m (2).ma := SR (2).ma
m (2).ps := strint (SR (2).ps )
m (2).ttl := strint (SR (2).mttl )
% flares
f (2) := strint (SR (2).f )
if SR (2).fw = "1" then
f2 (0).fw := true
elsif SR (2).fw = "0" then
f2 (0).fw := false
end if
for i : 1 .. f (2)
f2 (i ).fx := strint (SR (2).fx (i ))
f2 (i ).fy := strint (SR (2).fy (i ))
%f2 (i).fmx := SR (2).fmx (i)
%f2 (i).fmy := SR (2).fmy (i)
end for
end if
end if
end LANRead
|
Please specify what version of Turing you are using
Turing 4.1
【Edit】:
I add the code that used to connect in above.. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Wed Jun 01, 2011 4:30 pm Post subject: RE:Need help on the LAN Network Data Transmitting.. Too much Delay(ping).. |
|
|
Quote:
put : DataTransfer, SR (1).px
put : DataTransfer, SR (1).py
put : DataTransfer, SR (1).spd
put : DataTransfer, SR (1).shells
put : DataTransfer, SR (1).missiles
put : DataTransfer, SR (1).flares
put : DataTransfer, SR (1).DP
put : DataTransfer, SR (1).a
Is this seriously faster than a single binary transfer? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
DemonWasp
|
Posted: Wed Jun 01, 2011 4:53 pm Post subject: RE:Need help on the LAN Network Data Transmitting.. Too much Delay(ping).. |
|
|
You're probably waiting on a really really long timeout, because output is almost certainly buffered.
When you put some variable to the stream, it isn't immediately sent. Instead, it gets put into a buffer in memory, like a "TO DO" box. When enough things pile up in the to-do box, they are actually handled and sent over the network. However, if not enough things accumulate, then they will be sent after a specified delay (timeout). The reason for this is that there's a lot of overhead associated with sending one integer at a time instead of several hundred ints at the same time.
You could try using Stream.Flush or Stream.FlushAll, though I seem to recall that those weren't very usefully implemented. |
|
|
|
|
|
|
|