I have started to develop a simple MUD (text based multiplayer dungeon) where client uses only terminal to connect and play.
However i approached it the different way, i want the player to be able to move around the rooms (x,y) and see the map of a room like in the screenshot below
The whole screen as it is seen is being sent out by the server to the client on updates like:
somebody moved, something has changed in the current location, somebody dropped something, etc ...
At the bottom of the screen, there is a place where clients can put commands like:
look, east, west, pick up, drop, inventory, ...
Problem
The problem with the design however is, that when user is in the middle of putting a command and in meantime server has updated it's screen (somebody moved, or some event was generated ) he will loose the command he was typing because the whole screen got refreshed.
How do i send the screen to the player?
I build the view on the server side, and when sending to the client i use ANSI characters to:
Clear the screen (\u001b[H\u001b[2J)
Locate the cursor in specific areas of the window (\033[....) to draw specific areas of the view
Question
Is it possible, that clients don't loose their input when i send a view to them?
In other words, is it possible (maybe some ANSI code required?) that when i type something in the terminal and meantime if i receive something, my input is not broken by the newly received message?
To visualize the problem:
Good:
from server: aaa
from server: bbb
> input
Current:
from server: aaa
> in
from server: bbb
put
Alternative Solution
It's probably a better idea to construct the view on the Client side - then the server only needs to send the "raw information" and the client can display it. In this case, you've said the server sends a new view on events like someone moving - so just send a message to the client saying "Bob has moved", rather than an entirely new rendered screen, and let the client handle the update.
This has multiple advantages - to solve your problem, you can just buffer any server input until the user's finished typing, or redraw any bits of the screen that the client user's not actively changing.
It also allows for more customisation on the client side - if the server sends the view over, how does the client display it on a terminal that's a different resolution to the server's view? With client-side rendering, you can deal with this sort of issue on a per-client basis. You can also open up the door to massively more customisation by letting client users customise their personal views.
Workaround with your existing strategy
If you are fixed on having the server construct the views, then on the client you might be able to read single-character inputs at a time (on windows _getch, on linux ncurses provides this functionality), then if a server update occurs just render the new view and then re-render what the user's entered beforehand.
Another Suggestion
ANSI codes are... messy. Using a library like curses can make console-based-guis much nicer and more maintainable. On linux there's ncurses, and on windows there's an open-source variant called pdcurses (apparently has the same API, just exposed in an independent library. You'd need to change linker settings when compiling on Windows, but hopefully not any code). Thanks to Bartek for mentioning this.
Related
I am a new programmer in C++ with the EDSDK 2.14. I am using a Canon EOS 5D Mark II and i have some questions to do (i'm starting the api, camera session, handlers, set capacity,my program take photos, set the correct parameters to the camera and i'm using windows message to treat some events) :
1) I need to save the photos in the host pc, i am doing this correct, but the camera only permits like 8 photos in the internal buffer and i need to test some combinations of parameters (AV,TV and ISO SPEED). I make a loop to take 10 photos when i press 's' (with windows message, callback), and only 8 photos was taken, the others have busy error, so i guess that is the internal buffer. How can i take more than 8 photos, changing the parameters correct with one windows event?
ps: I tried to reopensession (close and open session with camera again) but was not a good idea, because the event handle of transfer (download image) was only set with the release of the object.
2) I tried to get one photo and download, but was not possible, when i press 's', the program wait to take the 8 photos, and after that the camera send the event callback to the handle for download all images. I want to press 's', and the program take one photo, download and take the others, if it is possible, how could i do this?
3) If i make a method to set the AV, TV , ISO Speed parameters, this will be sent to the camera in time to take the photo, or i need to wait something like a callback of the camera. If i need something like that, what event i need to use?
ps: my program is all asynchronous, i am not using threads, only callbacks and windows event.
4) I search in internet about to put the correct focus, but some people said that is only possible in live view, and i can't use this in my application. It is possible to change focus without live view?
ps: Because i need a good photo and the autofocus of the camera with my program, is not doing the same quality of images like the EOS Utility, and i am thinking if they have a pos-processing in the image taken or not
If i have more questions or i resolved the questions i will answer to all the community, because this too many guys are using this API and it's not too trivial. Sorry about my english, i am not native in this language, but i am trying to do my best.
ad 1) you need to download the image before the camera's internal buffer overflow, like you try in 2
ad 2) make sure your program, after sending the first shot commands, somehow comes back in the 'global' event loop. This should give the EDSDK a chance to process camera events and send "download available" events to your callbacks. Take it from there
ad 3) no guarantees whether these events are applied, you'd rather attach to a property change event (kEdsPropertyEvent_PropertyChanged) or poll some time after
ad 4) you can use liveview and lens-based AF. For the latter, explore kEdsCameraCommand_ShutterButton_Halfway
Care to share the goal of your project?
i have my application skeleton working as expected - it might be that somebody has a good solution to what i am trying to achieve within Windows Mobile 6.5 enviroment.
Here's what i am actually trying to do:
Application running in background ( it sends periodically network packets to office server, packets are loaded with statistics data and pushed onto the server via Winsock2 and custom made protocol ).
What 'background' means here - is an application that creates a window of 0,0 size and is minimized - i am thinking about going into the services with this, but the next thing that i require stops me today from doing this.
I need this application to be 'visible' somewhere as an icon - i already know i can't do this in the 'tray' area as stated in this post:
Windows Mobile C++ Tray Icon
Now i was trying to utilize the: SHNotificationAdd - but this is ok for a 'notification' as the name says type of thing. So it popsup and you can click to hide it - this is bad.
What i need to achieve is an icon that is visible during the application run cycle, so it flashes when there is no synchronization possible, it changes the icon when synchronization is done.
I am a bit worried it can't be done - i even tried to go and code the "Home" plug-in for this purpose, but was told that some people have themes installed and it might be that my application won't be even visible to those guys.
Now as we're going to deploy it to few places around ( 3 data centers spread across the country - around 130 people smart phones only ) - i need to be sure this application is visible even when there is a theme applied or customization done.
Any chance this can be done ?
I was kinda sure it can be done with a classic 'tray icon approach' until i found that 'tray icons' are not supported for normal applications.
If there is something i can do - i would really appreciate if somebody could shed a bit of light on this for us all please.
You'll have to move to a Windows Mobile paradigm for your app, as what you're trying to do isn't possible (as you're finding). A home screen plug in has problems if the user customizes it, and you are correct that there is no "tray". The icons in the corner (battery, signal strength, etc) are reserved for OEM use only.
My recommendation would be to actually create a visible Form for your application. Maybe it shows just some simple status info like last upload time, amount of data transferred, etc.
You then use the notifications to place a user notification during "events" such as the inability to connect (replacing your "flashing icon" idea) or when synchronization is complete (replacing your "changed icon" idea).
is there any sample project that shows how to use gamekit without gkpeerpicker? And is there any sample that uses bonjour (but without any internet connection and no wireless router)?
Some informations (for both projects):
only bluetooth (bonjour for the other project)
more than 2 devices (if possible)
server client model (how to make it work)
send/receive data
the server can decide whether is is "visible" for other "potenial" clients
show in a tableview the "discoverd" devices -> if the user clicks on a tableview cell (the name of the device e.g. "Tom's iPod Touch") it is going to pair up but the other user must accept the connection (UIAlertView) and if he accepts they will pair up
show all connected peers (connected to the server) in a uitableview
kick out some peers (only the server can kick other) (this should be easy to implement. just send a special packet to the client with a string that says "KICK YOURSELF" than it will kick itself)
invite other clients (in search)
(don't really need this but would be awesome):
let clients/server move objects (physic objects in box2d (cocos2d)) and than every client should show the exactly same simulation on the screen.
After using google for some hours I think there's no sample project(s) that shows these "features" above. Mayby someone could make one? Please do not say me some theory. I read so much but a sample project (or more and another for the bonjour version) with code commentary would be great!
Edit: I will probably add some bounty on this ;). Currently I can't ;)
Thank you very much for reading :)
cocos2dbeginner
I'm not going to write this for you but I can help with some information to get you started. There are many examples that show some of your features, particularly Apple's witap example.
One thing to note, you can't go from bluetooth to bonjour. bluetooth is the method of communication, bonjour is how you communicate. So you'd have to do bonjour broadcasting on one side and connecting on the other. Bonjour over bluetooth is taken care of in Apple's API, it should "just work". See this for some more info here.
This page from apple not only has gamekit concepts you are looking for but it also tells you the method names you will be using to get your tasks done, even if you don't want to be going through the supplied UI that apple has with GameKit.
Here, here, here, and here are links for more bonjour networking samples. As long as you're not doing complex tasks with sockets, I like this personally, it makes things very simple.
Hope that helps some.
I highly recommend Ray Wenderlichs page.
There is a tutorial for Gamecenter networking that matches some of your requests.
http://www.raywenderlich.com/3276/how-to-make-a-simple-multiplayer-game-with-game-center-tutorial-part-12
According to your alias: There are many more useful tutorials with a high quality. Go to http://www.raywenderlich.com/tutorials for a list.
Apple themselves have demo projects that show wifi connections using GKSession and Bluetooth using GKPeerPickerController. If you wanted a peerPicker and an option for both I think you need to use a peerpicker controller to give the user a choice. Use this code at the point you want the picker to appear, after you have instantiated the picker.
picker.connectionTypesMask = GKPeerPickerConnectionTypeOnline | GKPeerPickerConnectionTypeNearby;
Then if they choose wifi use the code from the GKRocket project in the iOS Sample Code Library. If they choose Bluetooth then use GKTank.
The GKRocket code (using GKSession and tables) is much harder to follow but GKSession automatically uses bluetooth if there is no wifi coverage. Given that you will need most of the code for GKSession in your project to handle wifi I think it is easier to forget about peerPickerController unless you only want bluetooth.
Eventually Apple will surely add the necessary methods and properties to peerPickerController to handle wifi, but for the moment it is GKSession you need.
Hope it helps.
I have been creating a 2D game in Qt and I want to allow others to connect to hosted games to play. Would I just make a "server" in the game and allow others to connect to it?
If this is just a small project and you aren't intended to mass distribute it across the web (it doesn't sound like you are), then you can code up a simple socket server. You will need to modify your existing game code to send the "moves" as a message to the server. It will probably be easiest if you make up a simple network protocol to transmit the move data (if you are ambitious you could try serialization).
A pseudo-code example for a simple Tic-Tac-Toe game:
move1 = "Move X:1:1" //placed an 'X' in square at row 1, column 1
move2 = "Move O:1:2" //placed an 'O' in square at row 1, column 2
reset = "Reset" //clear the board for a new game
...etc...
Your game code will need to generate these messages. Each player will run your game on their machine and this will act as the client.
Meanwhile, back in the server code, you will need to listen for move messages sent by the clients. When you get a move message, you need to broadcast the message to all the other clients so that there boards can be updated. I would recommend moving the server code outside of the game code for now; this will allow you to setup a dedicated server that will handle all the sockets and then everyone who wants to play will simply connect their client up to the server.
The basic idea is that your client needs to broadcast the details about what it's player is doing to the server, as well as listen for data from the server to update the details about the other player(s).
You can find some good discussion of high-level algorithms of a simple Client-Server game in this question as well: Algorithm for Client-Server Games
Hopefully this is enough to get you started! I have used this approach for some simple games (Tetris, Pong, etc) using C++/Qt and they worked out pretty well.
PS. Don't let the idea of writing your own server scare you off. It sounds daunting but it is really not very complicated at all (~100 lines of code or less) and a great learning experience.
Generally, one will need a few things to get something like that going.
Namely, a directory server. Maybe everyone connects to other players who host games to play, but you need to run a directory for games to be listed in order for people to connect.
Either that or you need to run a server and host them there. The choice is yours, the first option is probably easiest on you.
If I were you, I would make a server separated from, but bundled with, the "client". Believe me or not, many games out there take similar approach.
I need help trying to get thermal shipping label data from a Web site to a local Zebra printer. The data itself is just plain text but spooling it from a Web site seems to be very difficult for some reason. Does anyone have any experience with this? I am using ColdFusion 8 and Windows Server 2008.
Your print data could be sent with a MIME type (there probably is one for it, but you could make one up too)
On the client's PC, they could have that MIME type mapped to a program that simply prints whatever it receives.
Setting the MIME type on a PC can be done with code or a .REG file. If you control the user's environment, that's pretty simple. Making a program that dumps whatever it receives is also easy. That would be a nice task for Visual C or good, old VB6. Very little code. As long as the user has the .EXE and the .REG file, they'll print reliably, every time, without the browser's crap getting in the way. (think of this as what happens when you click a link to a PDF - Acrobat opens. Well, have the little printing EXE open for your file type - easy).
This is familiar to me... I think I did this with a proprietary font set... AH! Yes, I had to do this to generate mortgage documents that used proprietary fonts for drawing the pretty lines. I was able to take a proprietary, stand-alone mortgage origination server, share the folder where the mortgage .PRN files had been created. A Web server with access to that share enumerate the files in the share to a Web page, then, when users clicked on a file, the .PRN would stream to their PCs where a corresponding .EXE would see it as one of its own and send it to the correct output device (a designated printer at their location). That dumb little piece of code eliminated 126 document servers (and their maintenance and licensing costs) instantly and mortgage documents were never lost or sent to the wrong branch by mistake again. I think it took 3 hours to get it all working from inception to testing at the branches.
Yeah, same thing here. It'll work. Trust me. It'll work.
I was unclear by your question as if the Zebra printer is connected to the web server and what software the server is running. If you are trying to send the data to a printer connected to the web server, I used the following information to send label data to a Zebra thermal printer in an Intranet solution and it worked great:
How to send raw data to a printer by using Visual C# .NET
Perhaps you can adapt this solution to your environment.
I fiddled about with this problem for ages. In the end I had to create downloadable printfiles. The user downloads them and then copy (MSDOS) them to the printer.
There were two main issues:
generally speaking, you can't print
from a website unless you open the
file (ie the file becomes local)
the print drivers on the user's (Windows)
machine add non-printing characters
to the barcode file as it is sent to
the printer
We installed a batch file (which runs copy instead of print) on all client machines that need to print barcodes and we added a right-click menu item to run the batch on files named *.barcode.
I'll be watching this thread to see if anyone has found a more direct solution. But this was the only thing we could do given the parameters of our situation.
I don't know if I have fully understood your problem or the exact environment but I have answered a similar question here with an example for ASP.NET (C#). That solution is mainly for a known printer (specific IP and port). If you have several clients with their own label printers the solution could be used for that as well. But then you have to make a solution where the clients are able to set their own IP and port of their label printer. They also might need to make a port forward for the traffic in their firewall. The webpage then just prints to the specified IP and port. You can also use a domain name instead of IP.
Perhaps you could try this:
http://code.google.com/p/jzebra/
This project allows the ZPL commands to be sent to the printer via a web browser.