Computer Science Canada Sending Graphics over net |
Author: | Khrist [ Thu May 26, 2005 9:09 am ] |
Post subject: | Sending Graphics over net |
Ive been trying to make a simple lan game for my final project. I understand most of the net commands and can create and successfully run a simple chat server/client. However, ive created numberous offline games which ide like to be able to adapt to online. I cant seem to figure out, or find a post which explains how to send images/graphics anything like that over the stream. If anyone can explain and maybe give an example as to how to do this it would help me out a lot. Thanks |
Author: | Tony [ Thu May 26, 2005 2:36 pm ] |
Post subject: | |
you've got to send binary information and then reconstruct the file using bits and bites. I don't remember if Net. can send binary data, so if you're using strings, remember that each character is actually 8 bytes. You'll be able to send 800% more data (well... technically 7/8 less junk) if you are to construct datastrings from binary and then decode. intstr(), strint() and understanding of binary algebra could be of use. |
Author: | c0bra54 [ Thu May 26, 2005 2:55 pm ] |
Post subject: | |
wouldn't it be infintly easier.. yet take insanely more time, to simple use whatdotcolour, for every pixel of the screen, and send every single pixel,m and have the client (other end) reconstruct the image use drawdot... it's insanely more complex.. but would it work.. OR you could write a file compresiong to use in turing, like say what dot colou pixel 1 what dot colour pixel 2 and thn say if what dot colour pixel 2 is = to whatdot colour pixel 1 then send (x,y) of pixel 1, hello client, pixel 2 is the same as pixel 1!! and poof file compression is born!!! lol kevin.. PS if you do nytihng with that.. post it it'd be sooo cool |
Author: | Carino [ Thu May 26, 2005 3:53 pm ] |
Post subject: | |
Even if you could send pictures and what not, it would be EXTREMELY slow using turing. I suggest you have all pictures stored on both comps, and then just have the server send the coordinates of specific pics or vise-versa. Then you can just draw the pics using the new coordinates. |
Author: | Token [ Thu May 26, 2005 5:35 pm ] | ||
Post subject: | |||
okay, i made this to try and help, but it dosent seem to re-daw or copy it properlly, probibly just a brain fart somewhere along the line, ne ideas? |
Author: | Cervantes [ Thu May 26, 2005 5:57 pm ] | ||||
Post subject: | |||||
Say we set the graphics of the original screen to 200 by 200:
We entered the numbers 200 and 200, but maxx and maxy return values of 199 and 199. You can verify this by looking at your file. So, when we reconstruct the second window, we must add one to your screenx and screeny variables. Completed code: (I also changed the code a little so we don't have to close then re-open the file.)
|
Author: | McKenzie [ Thu May 26, 2005 7:19 pm ] | ||
Post subject: | |||
I find takepic the best for this
Be carefull because I think it only works if you are in the same resolution (or at least colour depth) |
Author: | Token [ Thu May 26, 2005 8:03 pm ] |
Post subject: | |
thanks for the help Cervantes, yah that would be the deciding factor :p ne ways the reason i made it open and close twice is because one side is the client and the other the host, i just havent added the Net commands yet. |
Author: | c0bra54 [ Thu May 26, 2005 9:54 pm ] |
Post subject: | |
wow guys nice work on this.. but mainly i am thinking, like what about if you wanted o do a sort of paint program.. or somethin like msn whiteboard (if nyone else has used it) but this is insane.. if anyone wants to swap msn maybe we could setup a net vers and see if it works.. i have router and it won't let me using turing net (tried) so blah ![]() |
Author: | Khrist [ Fri May 27, 2005 8:05 am ] | ||
Post subject: | |||
ok ive read over everything and i like the idea of sending variables(x,y) and then just have the client update thier screen. It could use universal variables like x1pos,y1pos,x2pos,y2pos which would be declared on client and server. Then the player 2(x2pos,y2pos) would only be available to change on the client. For instance the controls for player 2 only work on the client and the controls for player 1 only work on server. Then it swaps the co-ords and updates. I dont think ill be able to do a tag game becasue it wouldnt update fast enough. But i have some other ideas. Anyways im not quite sure how do go about sending variables, i know how to send text but how to you send something that would change the clients vars? Is it close to this?
Thats whats in my head but im not sure. Ill go experiment with some things and maybe ill find it out myself, but if not maybe someon could clear it up for me. Thanks again everyone. |
Author: | c0bra54 [ Fri May 27, 2005 8:18 am ] |
Post subject: | |
you need to send a header... a header is somehting at the begining of w/e u send that tells the over machine what you are doing, so like your getcould be, get:header if header = w/e then get w/e end if that way the client knows what it is that it is getting information wise... it gets to be really long, when you have like 40 differnet things you need to send ![]() but yeh, use a header |
Author: | Khrist [ Fri May 27, 2005 8:37 am ] |
Post subject: | |
Ok, cobra i read what you wrote but im not really clear on what it means. I asked my teacher if he understood it and he didnt. Would you be able to write a sample code of that snipet just so its a little more clear. Thanks for the help. |
Author: | c0bra54 [ Fri May 27, 2005 9:23 am ] | ||
Post subject: | |||
umm yeh sure.. gimme a sec PS i dun knwo if this will work or not since i un have turing open.. and his hasn't got the net in it
this is an example, where the user oulkd enter the name of what he wants to change, then the new value... and you have a header var which is what is being changed, and then an info var for the data that is being sent... you could also do this in an array format which could meen you don't need to send a header.. like the other machine knows that data(1) is xpos data(2) is ypos data(3) is colour or w/e \ the only problem with that is it needs to send all of them, other wise the machine reciving will get messed up... because remeber you can only send text... so even if something didn't change you'd still need to send it... ![]() hope that clears things up.. if not tell me |
Author: | Carino [ Fri May 27, 2005 10:39 am ] | ||
Post subject: | |||
I made a net pong game, and i tried transfering variables various ways. One way was to have one stream for each variable then just send the info through the stream when need be. Another way i did it was to add a number to each variable, such as 1000 to the x, and 2000 to the y variable. Then i would have an if statement checking each number such as:
Either way though, it was really slow. It worked, but slowly. |
Author: | McKenzie [ Fri May 27, 2005 4:33 pm ] |
Post subject: | |
I find it's best if you only pass the players moves over the net. Take a look at my connect 4. Very simple system. |
Author: | wtd [ Fri May 27, 2005 4:44 pm ] |
Post subject: | |
McKenzie wrote: I find it's best if you only pass the players moves over the net.
Absolutely. In general, when dealing with networks, only send the information that's absolutely necessary. That way you can build clients that are free to add features or just interpret the moves differently, without having to change how you send the data or the data format itself. |