It seems that if I shut down the server, then start it on the same ip and port, if the clients haven't disconnected, then they are still sort of connected as far as they're concerned and can still send data to the server
Oops
[QUOTE=origamiguy;33366083]Methodically running HTTP GET on every IP on my subnet at uni accommodation
[IMG]http://i.imgur.com/VTfge.png[/IMG]
It's going well...[/QUOTE]
Oh god I wrote something like that but to random IP's.
You know you can use Nmap do that for you as well?
[QUOTE=Matte;33360790]Loops are now compiling splendidly (both while and for loops). It is also possible to isolate your code with blocks (view code below). I also have a basic implementation of arrays done. It will probably be extended to support n-dimensional arrays.
[img_thumb]http://i.imgur.com/LPRHP.png[/img_thumb]
The code in the picture:
[code]function int[] main(bool returnArray)
{
int[] array = { 16, 2, 77, 40, 12071 };
for(int i = 0; i < 5; i++)
{
print(array[i]);
}
// Isolated block
{
int i = 0;
while(i < 5)
{
print(array[i]);
i++
}
}
if(returnArray)
{
return array;
}
else
{
return { 0 };
}
}[/code][/QUOTE]
That's pretty good, and it seems a bit more fleshed out than the compiler I wrote for a class I had a year back. It's ridiculously minimalistic, but I might rewrite it when I have the time for it.
[cpp]int LF; /* Line feed */
int gcd (int a, int b)
{
/* Computes the gcd of a and b. */
while (a != b) {
if (a < b) {
b = b-a;
} else {
a = a-b;
}
}
return a;
}
int main ()
{
int v1;
int v2;
LF = 10;
putchar('?');
putchar(' ');
v1 = getint();
v2 = getint();
putint(gcd(v1, v2));
putchar(LF);
}[/cpp]
It compiles into (very unoptimized) x86 gasm:
[cpp] .data
.globl LF
LF: .fill 4 # int LF;
.text
.globl gcd
gcd: pushl %ebp # Start function gcd
movl %esp,%ebp
# param: int a;
# param: int b;
.L0001: # Start while-statement
movl 8(%ebp),%eax # a
pushl %eax
movl 12(%ebp),%eax # b
popl %ecx
cmpl %eax,%ecx
movl $1,%eax
jne .L0003 # Test !=
movl $0,%eax
.L0003:
cmpl $0,%eax
je .L0002
# Start if-statement
movl 8(%ebp),%eax # a
pushl %eax
movl 12(%ebp),%eax # b
popl %ecx
cmpl %eax,%ecx
movl $1,%eax
jl .L0006 # Test <
movl $0,%eax
.L0006:
cmpl $0,%eax
je .L0004 # Skip to else-body
movl 12(%ebp),%eax # b
pushl %eax
movl 8(%ebp),%eax # a
movl %eax,%ecx
popl %eax
subl %ecx,%eax # Compute -
movl %eax,12(%ebp) # b =
jmp .L0005 # Skip else-body
.L0004: # Start else-body
movl 8(%ebp),%eax # a
pushl %eax
movl 12(%ebp),%eax # b
movl %eax,%ecx
popl %eax
subl %ecx,%eax # Compute -
movl %eax,8(%ebp) # a =
.L0005: # End if-statement
jmp .L0001
.L0002: # End while-statement
movl 8(%ebp),%eax # a
jmp .exit$gcd # Return from gcd
.exit$gcd:
popl %ebp
ret # End function gcd
.globl main
main: pushl %ebp # Start function main
movl %esp,%ebp
.data
main$v1:
.fill 4 # int v1;
main$v2:
.fill 4 # int v2;
.text
movl $10,%eax # 10
movl %eax,LF # LF =
movl $63,%eax # 63
pushl %eax # Push parameter #1
call putchar # putchar(...)
popl %ecx # Pop parameter #1
movl $32,%eax # 32
pushl %eax # Push parameter #1
call putchar # putchar(...)
popl %ecx # Pop parameter #1
call getint # getint(...)
movl %eax,main$v1 # v1 =
call getint # getint(...)
movl %eax,main$v2 # v2 =
movl main$v2,%eax # v2
pushl %eax # Push parameter #2
movl main$v1,%eax # v1
pushl %eax # Push parameter #1
call gcd # gcd(...)
popl %ecx # Pop parameter #2
popl %ecx # Pop parameter #1
pushl %eax # Push parameter #1
call putint # putint(...)
popl %ecx # Pop parameter #1
movl LF,%eax # LF
pushl %eax # Push parameter #1
call putchar # putchar(...)
popl %ecx # Pop parameter #1
.exit$main:
popl %ebp
ret # End function main[/cpp]
[QUOTE=Anonim;33368610]It compiles into (very unoptimized) x86 gasm:[/QUOTE]
That's awesome. I'd love to learn assembly and write my own compiler sometime.
But for now, more physics!
[img]http://dl.dropbox.com/u/11093974/Junk/20111121_0335_09.gif[/img]
Balls on (invisible) bungees.
Quick question : Is there any difference in speed when itterating through a array of int or a array of structs with a couple of ints in each struct ?
[QUOTE=quincy18;33369393]Quick question : Is there any difference in speed when itterating through a array of int or a array of structs with a couple of ints in each struct ?[/QUOTE]
Depends entirely on what you are doing inside the loop.
[QUOTE=ZenX2;33367884]It seems that if I shut down the server, then start it on the same ip and port, if the clients haven't disconnected, then they are still sort of connected as far as they're concerned and can still send data to the server
Oops[/QUOTE]
Hmm, that shouldn't happen. As soon as the process ends, the OS should close the connections automatically (e.g. by sending TCP FIN packets). Check with wireshark and see what's really happening.
[img]http://i.imgur.com/xV7o5.png[/img]
Pretty much done with level buttons.
[QUOTE=Robber;33369474]Depends entirely on what you are doing inside the loop.[/QUOTE]
Accessing each variable and assigning numbers to them in the struct and for the int array I am doing a couple of shifts.
[QUOTE=layla;33367262]displacement lightmaps :)
[img]http://dl.dropbox.com/u/99765/bsp678.png[/img][/QUOTE]
OMG the grafx r bettr than gmode
[QUOTE=Anonim;33368610]That's pretty good, and it seems a bit more fleshed out than the compiler I wrote for a class I had a year back. It's ridiculously minimalistic, but I might rewrite it when I have the time for it.
[cpp]#code[/cpp]
It compiles into (very unoptimized) x86 gasm:
[cpp]#code[/cpp][/QUOTE]
That's really nice. I'm compiling to NASM (x86) at the moment, though I'm far from finished writing the class hierarchy->assembly code.
Come to think of it, compiling directly to x86 machine code would be extremely cool. Maybe I'll do that. Shouldn't be too hard, as I already know the layout of the assembly code, and don't need to preprocess it.
Time for a rousing game of Spot the Compilation Error: C++ Edition!
[cpp]
// drwModel.h
float *colConvexHull;
uint32_t colConvexHulls;
// drwModel.cpp
mdl->getConvexHull(&colConvexHull, &colConvexHulls);
// resModel.h
void getConvexHull(float** buf, uint32_t* bufs);
// build output
res/resModel.cpp:325:25: error: no matching function for call to 'res::resModel::getConvexHull(float*&, uint32_t&)'
res/resModel.cpp:325:25: note: candidates are:
res/resModel.cpp:318:20: note: btConvexHullShape* res::resModel::getConvexHull()
res/resModel.cpp:318:20: note: candidate expects 0 arguments, 2 provided
res/resModel.h:61:8: note: void res::resModel::getConvexHull(float**, uint32_t*)
res/resModel.h:61:8: note: no known conversion for argument 1 from 'float*' to 'float**'
[/cpp]
[sp]The error is in res/resModel.cpp, why are you looking in gk/drwModel.cpp? (The output window in NetBeans linked me to drwModel.cpp instead of resModel.cpp for god knows what reason.) (A.K.A. Red Herring Bug)[/sp]
[cpp]import java.util.Scanner;
public class Hello_World {
public static void main(String args[]) throws InterruptedException{
Scanner input = new Scanner(System.in);
int firstnum, secondnum, answer;
System.out.println("Enter your first number: ");
firstnum = input.nextInt();
System.out.println("Enter your second number: ");
secondnum = input.nextInt();
answer = firstnum + secondnum;
System.out.print("The answer is ");
System.out.println(answer);
Thread.sleep(1000);
while (answer >= 0){
answer += 5;
System.out.println("Adding 5...");
Thread.sleep(1000);
System.out.print("Your new number is ");
System.out.println(answer);
switch (answer) {
case 20: case 30: case 40: case 60: case 70: case 80: case 90:
System.out.println("");
System.out.println("It appears " + answer + " is a multiple of 10!");
System.out.println("");
break;
case 50:
System.out.println("");
System.out.println("JESUS CHRIST IT'S HALFWAY TO ONE HUNDRED");
System.out.println("");
break;
}
Thread.sleep(1000);
if (answer >= 100){
System.out.println("Finished adding!");
System.exit(0);
}
}
}
}[/cpp]
My first time with Java, putting what I just learnt to use. Is it of acceptable standards?
[QUOTE=LuckyLuke;33372973][code]//code[/code]
My first time with Java, putting what I just learnt to use. Is it of acceptable standards?
I also don't know if there are any java tags, so for now I used [code].[/QUOTE]
You can use [noparse][cpp][/cpp][/noparse]. One thing I can suggest is declaring variables where you need them. In this example it doesn't make a whole lot of sense, but in really big methods where you need over 10 variables it makes it much easier to read. Also I'd use ifs instead of the switch-case.
[cpp]
if(answer==50){
//...
} //put an else here if you don't consider 50 a multiple of 10
if(answer%10){ // % means modulo. It's returns the rest of the division. For instance 15/10=1 and 5 rest which means % would return 5
//...
}
[/cpp]
[QUOTE=Robber;33373136]You can use [noparse][cpp][/cpp][/noparse]. One thing I can suggest is declaring variables where you need them. In this example it doesn't make a whole lot of sense, but in really big methods where you need over 10 variables it makes it much easier to read. Also I'd use ifs instead of the switch-case.
[cpp]
if(answer==50){
//...
} //put an else here if you don't consider 50 a multiple of 10
if(answer%10){ // % means modulo. It's returns the rest of the division. For instance 15/10=1 and 5 rest which means % would return 5
//...
}
[/cpp][/QUOTE]
Thankyou, i'm relatively new to Java so any help and improvements are appreciated :v:
My server only appears to allow one client, if 2 sockets are open then the 2nd user is ditched behind in the dust.
[QUOTE=Map in a box;33373868]My server only appears to allow one client, if 2 sockets are open then the 2nd user is ditched behind in the dust.[/QUOTE]
You cannot have multiple connections from the same socket or share a single port with TCP.
Typically, if using TCP, you'd dedicate one port to handshaking, then when a client connects you go "hey, go to port [i]x[/i], that's your port!", then the client re-connects to that port.
However, you might want to look into UDP. Depending on your application, UDP might make more sense. Unlike TCP, UDP [i]does[/i] allow multiple peers to connect to the same port.
Sand game for the console :V ;
[img]http://i56.tinypic.com/jzgzk8.png[/img]
Nah, needed to confirm if my array worked.
[QUOTE=ROBO_DONUT;33373953]You cannot have multiple connections from the same socket or share a single port with TCP.
Typically, if using TCP, you'd dedicate one port to handshaking, then when a client connects you go "hey, go to port [i]x[/i], that's your port!", then the client re-connects to that port.[/QUOTE]
Are you sure of this?
I vaguely remember using a single port for the server when toying around with networking ages ago. It'd listen on multiple sockets through a single port, and it worked fine.
Mind you, I've forgotten almost everything about network protocols and may be very wrong.
[QUOTE=Anonim;33374502]Are you sure of this?
I vaguely remember using a single port for the server when toying around with networking ages ago. It'd listen on multiple sockets through a single port, and it worked fine.
Mind you, I've forgotten almost everything about network protocols and may be very wrong.[/QUOTE]
In Java I always just opened one server socket and accepted clients that all connected to that one port and got a Socket object back for each client and used them to communicate with that client. I'm not sure if Java did some background magic to automatically do the handshaking and reconnecting, but I doubt it.
[QUOTE=Robber;33374576]In Java I always just opened one server socket and accepted clients that all connected to that one port and got a Socket object back for each client and used them to communicate with that client. I'm not sure if Java did some background magic to automatically do the handshaking and reconnecting, but I doubt it.[/QUOTE]
Well, I haven't tried networking in Java, but I distinctly remember it being slightly more frustrating in C.
[editline]21st November 2011[/editline]
I'm looking through some of that old networking code I wrote in C, and I can't figure out what the hell is going on even though I documented it fairly well.
I remember why I stopped doing networking now, though. What a god damned fiddly mess.
[QUOTE=ROBO_DONUT;33373953]You cannot have multiple connections from the same socket or share a single port with TCP.
Typically, if using TCP, you'd dedicate one port to handshaking, then when a client connects you go "hey, go to port [i]x[/i], that's your port!", then the client re-connects to that port.
However, you might want to look into UDP. Depending on your application, UDP might make more sense. Unlike TCP, UDP [i]does[/i] allow multiple peers to connect to the same port.[/QUOTE]
No no, I .accept() new clients, not one socket for the entire session.
Anyone know of a good resource to learn 2d normal mapping? I don't quite get the concept.
Am I the only one who suffers from off-by-one errors when it comes to modulos and string lengths?
[QUOTE=Anonim;33374502]Are you sure of this?
I vaguely remember using a single port for the server when toying around with networking ages ago. It'd listen on multiple sockets through a single port, and it worked fine.
Mind you, I've forgotten almost everything about network protocols and may be very wrong.[/QUOTE]
My mistake. I haven't done anything with TCP in a very long time.
I feel like an idiot now, since I actually remember doing something like this with TCP before.
[QUOTE=Nigey Nige;33375129]Anyone know of a good resource to learn 2d normal mapping? I don't quite get the concept.[/QUOTE]
It's basically the same as 3D normal mapping.
You can throw out the z-component (typically blue) of the normal map and only use the x- and y- components (red and green) because z=0 for 2D games. It's even simpler because you don't have to worry about tangent-space conversions. Tangent space is equivalent to object space for a simple tile-based engine, and for just about anything else it's just a simple matter of rotation.
I tried pathfinding
[img]http://puu.sh/95iS[/img]
oops
EDIT:
[img]http://puu.sh/95ld[/img]
WHY WOULD YOU DO THAT
[QUOTE=Jookia;33375653]Am I the only one who suffers from off-by-one errors when it comes to modulos and string lengths?[/QUOTE]
That's the number 1 error that happens. Or Number 2, I'm not quite sure now.
[QUOTE=Map in a box;33375006]No no, I .accept() new clients, not one socket for the entire session.[/QUOTE]
I don't think it has anything to do with the actual networking protocol or sockets at this point, likely your code is not set up to handle both clients concurrently. You need to either handle connections in separate threads or switch between connections periodically.
This is just a guess though, you're only giving us little bits of information with no code.
[QUOTE=Ploo;33375685]I tried pathfinding
[img]http://puu.sh/95iS[/img]
oops
EDIT:
[img]http://puu.sh/95ld[/img]
WHY WOULD YOU DO THAT[/QUOTE]
My guess is that moving diagonally is "cheaper" than moving vertically?
[QUOTE=DrLuke2;33376006]My guess is that moving diagonally is "cheaper" than moving vertically?[/QUOTE]
Actually the cost was the same straight straight/diagonally and I'm guessing it would end up often evaluating a diagonal path first. Made the cost of diagonal movement root(2) and it's fine now. :)
Sorry, you need to Log In to post a reply to this thread.