I have a game called wizard wars that I have been working on. This game needs to allow 2 players to play at one time, and would need a TCP connection to communicate spell creation/destruction ect., and a UDP connection to handle locations ect. It would have a client and a host side. That being said my program is designed to run on Android. All of the tutorials/information I have found online has been for JApplets or something like that. So what I would like is some help with ever short code examples of how to set up/use connections, or just a link to some sufficiently helpfull information on how to set up the actual connections.
The best approach (or at least 1 approach) would be to use normal HTTP requests : http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Net.html
You create a webservice implementing REST and create calls for both updating and consuming data.
Alternatively, if you're just going to use Android and Desktop you may also use WebSockets : https://github.com/pepedeab/libGDX-Net
For those who don't read comments, but still looking for tcp client.
You can use KryoNet which supports Desktop and Android
https://github.com/EsotericSoftware/kryonet
Have you guys looked at the multiplayer super jumper tutorial? Its written using AppWarp and is being actively used in the libgdx community as well.
Related
I have developed a simple file sharing application in java using TCP socket. Now, the question is how do i make this application P2P? Can Distributed Hash Table (DHT) do that or there are other options that i can implement in my application to make it P2P? I have been trying to get ideas on this for a long time but i only get more confused. Please help.
The Forest platform which is in early development is targeting applications like your. You might want to take a look at it.
The only problem is that it is still in development and is not yet usable. I advise you to keep an eye on it and try to use it once it reaches it first release.
EDIT to answer the comment under your question:
Your application would need to connect the some peers. Depending on how you choose them (random people or know contacts), you are using respectively a peer-to-peer ('p2p') network or a friend-to-friend ('f2f') network.
Forest is providing applications a f2f network, but application are free to route messages on the top of this network to achieve (anonymous) p2p.
For a classical p2p network, you would need to connect a DHT, and you would need to bootstrap to it via a (or some) server(s) which take part in the DHT.
In general, p2p application are not so simple to do, and you will need to deal with a lot more details here and there. If you really want to experiment with them, you can go to check existing DHT libraries and see how they work. You might first want to go to read the article on Wikipedia about Kademlia which is the base for the most used DHT algorithms.
Based upon your description it sounds like you have already created a simplistic P2P application. If you are looking for the next step I would setup a DHT server (bamboo). Next, modify your original application to get a list of available files from the DHT instead of connecting directly to the other peers for file lists.
I develop a simple P2P file sharing application in java too,but i find it hard . If you write it in java . You can search for Vuze or jBittorrent , which may help you develop it faster.
I want to create http socket connection for server in php for multiple client . how can I do that ? I need some resource .
First I was trying to create server in java .I create a server in java . And trying to reach from android application .But server can't find any client.But when I create client in java .It was working. How can I solve that problem ???
Take a look at this article:
Writing Socket Servers in PHP by Zend
Also give a try with Google:
http://www.google.com/search?aq=0&oq=php+socket+server+mul&sourceid=chrome&ie=UTF-8&q=php+socket+server+multiple+clients
Personally I think this would be a pretty bad idea, as already mentioned it lacks Threading and it's Socket support (imo) isn't really that adaptable.
The only plus side is that you can use fork to fork off another PHP process to handle a client, but you're getting very complex.
Another language would be much more suited for this type of development.
Note that even if you did do this in PHP, you'd probably have to rely on external services anyway, and possibly even end up writing at least some code in another language anyway.
You're trying to use PHP to do what? Mind you, I like PHP and work with it almost every day, but please do remember PHP in and on itself is based on request and response, and not very suitable for long running processes. In a manner of exercise, it might be interesting, but if you're trying to write a webserver from scratch using PHP, you might want to reconsider your choice of language.
That said, you can create a socket acting as a server, and listen to incoming packets. I do still think you're reinventing the wheel though.
though i love php and java, i wrote my socket servers in c++ running under lamp in an amazon ec2 cloud server. it is very, very simple to code and debug and safe and you can practically just copy/paste examples.
in the long run, i will probably develop a java solution because of portability and scalability, but the initial effort to get a c++ solution working is just so much less than implementing a java solution...
the first thing you must ascertain (find out) is whether your server allows you to open custom ports. amazon ec2 does and at this point in time (feb13), can be used for free for 12 months.
so, this is for you if you are in a hurry:
this here set of examples has all that you need to be up and running in no time.
Judging from the question title (the rest only makes it more confusing) you could use an existing package like http://pear.php.net/package/HTTP_Server to implement a webserver in PHP. It already contains all the socket code to accept client connections and stuff.
So what i have to do to find the server from different client
"Finding" is too broad a topic. Depends on your actual setting. On a LAN there are some protocols for discoverability. Otherwise you should just rely on a fixed machine name and port number for your instantiated server. You can connect to it as e.g. http://localhost:8007/ or whatever you've predefined.
i want to know how can i make some thing like skype or yahoo messenger ?
i mentioned yahoo or skype because really i want the messenger to handle many online users.
i am a java developer, but i don't have any idea for this kind of projects or either for VOIP and networking ?
can i develop some thing like a messenger only with java ?
and what other technologies, frameworks or any thing else i need to handle this project ?
at the end, can i develop it alone ?! or i need a team to start ?!
I guess that what you need most is knowledge about network programming. This is the first step towards your goal: you'll learn how to communicate between two hosts and among several ones in a reasoned way (some link for java net programming here, here and a book here ). Focus your attention on protocols (low level ones) (and maybe cryptography) and try to spot the right one for your needs. You'll have to understand even ifyou want to write your own IM protocol (high level one) or use one of the existing ones (Jabber, MSN, Yahoo, aim, etc)
Secondly, you could have a look at an open source project that tries to implement something similar in order to understand better how to structure your project architecture, client communications and so on. You can start looking at some lib (here is one for java and Jabber, here for Yahoo) around the web too.
Finally you can start design your project and decide if the work to do is more than a single person can bear in a reasonable time and try to convince people work with you. Or you could also join an open source project if you find any.
Why reinvent the wheel. There are many open source software in JAVA available which supports IM, multiple chats, presence as well as voice and video calls.
Skype is based on SIP + its own proprietory technology. So skype will only work with skype. Forget about interoperability
Gtalk uses XMPP (www.xmpp.org) for its chats, but uses libjingle(for RTP sessions) for audio/video calls. (The libjingle protocol and Jingle are very similar, they are not the same, and are not interoperable)
Yahoo, Facebook... there are many IMs which are now moving to XMPP. (Why..??? because of interworking)
So if you want to create your own IMs which interworks with gtalk, yahoo... all the available IMs, use XMPP libraries. To start with you can download JAVA version of XMPP - SMACK. Use its simple APIs and your IM is ready.
So if you really want to do something interesting come up with new features, contibute to open source community, patent your idea/technology or sell it to big guns. :)
You probably want to research on socket. A lot of socket application made by java btw. For simple chat application it is. However video chat or VOIP needs a lot more effort.
Explore java.net
Learn socket programming, ain't that complicated.
About handling multiple clients, you server would have to have multiple threads. One for each client.
Developing a simple chat messenger is not that a bid deal in java. One can do this on its own.
Probably, you can even handle multiple clients with multi-threading.
I've been developing a small card game which is called "Tarneeb". The game itself looks like Bridge card game but with different rules. Anyway, i finished the entire game as a standalone desktop application using Java 6. This is a picture of the game. Anyway, i now need to transform that into a web app with multiplayer capabilities, so the users can for an example make a new room and join existing rooms where the game is played.
Unfortunately, I have no idea on networking in Java but i searched quite a lot and i found some other Java products that may help me (JavaFX, JSP, GlassFish) but i still couldn't figure out what i exactly needed to accomplish my task. All i need right now is the direction to head to and i will do my research and hopefully learn the new skills needed.
Other answers have already pointed you to some resources.
But the biggest problem you will likely have is that it is usually impossible (or extremely time consuming up to a complete rewrite) to "add" multiplayer capabilities afterwards if you didn't plan the architecture accordingly.
As you might have a lot of interaction and a lot of updates which I should - correct me if I'm wrong - be at the client as fast as possible, I'd suggest having a look at Cometd which keeps the http connection open to each client and pushes the updates from the server to the client. If you're using jetty as webserver (and thus its "continuations") it's even highly scalable.
The thing is, there isn't one standard way of doing this which you need to read up on.
How do you want to implement this web application? As an applet? Using standard web pages? As a web start application which people have to download?
The last option would allow you to re-use most of your existing code. If you go with that option it may be worth you looking into RMI as that will probably fit in with your existing architecture.
But otherwise, as S.Lott pointed out, you need to go and learn how to make web applications before doing anything else. Those tutorials would be a good start, also you should definitely learn (X)HTML, JavaScript, and a Java web technology such as JSPs, JSF, or Struts. Exactly what you need will depend on your requirements, without more details it's diffiult to recommend one.
First, learn what a "web site" and "web application" are.
Do the tutorials: http://java.sun.com/developer/onlineTraining/index.jsp
Watch the Glassfish Tutorials: http://java.sun.com/javaee/overview/screencasts.jsp
Once you've done all the tutorials, you will have built a web application.
After you've built the tutorial web application, you can build your web application.
Web apps are very badly suited for the kind of realtime interaction you have in a card game. Yes, it can be done, but it will involve dirty hacks and you'll always have problems with high latency and broken connections. And of course you'll have to completely rewrite most of your app.
If there a possibility of running the game as a Java applet? That would make your job much easier (enable much more reuse) and the end result more usable.
There is no way to port a client based app into a web app quickly. Depending on how you want to go about it, it sounds like you either need to pursue a JSP/Javascript solution or a JavaFX solution. JavaFX actually allows for smoother (smoother than JSP/Javascript, but still going to take more than an afternoon =D ) porting of client based apps, but it has a steeper learning curve than JSP/Javascript technology in general. An interesting note here is that JavaFX isn't just a web app language. If you had coded your initial client based app in JavaFX, you would have about 50% of the work done.
JavaFX
Use Java NIO, it is quite simple and if you will grasp the basics, there would be no real need in all these countless libraries... or anyway you would know their internals. One of the important things however, mentioned here already, is that the game structure has to be adapted for networking from the start. It may be a complete rewrite in the worst case. Basically, you will have to create clients database, socket connections, and from the server side, every connection (represented by a SelectorKey object), should be encapsulated into an object, representing a "joined client". Then read/write operations would be performed to the key's socket. But there is more. The server will have to be the center of your application link, so that you will have to develop an entire network messages protocol for your game (over TCP, there is no need in UDP in this kind of game). Also - read more about the protocols (TCP/UDP/sockets, ethernet), the more you read - the better.
Also! Pay attention to the HTML5 websockets stuff. It is a great thing!!!
im developing a multi-player card game that needs the clients to communicate with each other or a general server. i have never done this before so i need some direction or tutorial on how to achieve this.
so far i have created the local, single person version of the game...
Sun has a good tutorial on writing a client/server pair complete with code examples.
So far i have created the local, single person version of the game...
Great, I would suggest to continue with the local multi-player version of the game ( even when it is controlled by the same "terminal" )
From there you may explore RMI to invoke the methods remotely. It should be much more simpler than creating the multi-player version and add networking.
What RMI does is to abstract the network connectivity and allow you to simplify the execution of remote objects call ( that is, it simplifies having to write your own protocol with sockets )
RMI is more complex. You need to understand some concepts before starting with RMI, like extending Remote, RemoteExceptions, etc. And also, running applications powered by RMI require some steps, such as starting rmiregistry, and setting a policies file.
If you are a beginner, start with simple sockets first. They are easier to understand, but somewhat long to code. RMI is easier to code, but somewhat tough to understand.
For Sockets:
TCP Sockets
UDP and Datagrams
For RMI:
Simple tutorial to RMI - Really helped me start