Instant Messenger,Java 基础项目
我目前正在尝试使用 Java 创建一个非常基本的即时通讯工具。
我有点不知从哪里开始,想知道这里是否有人可以推荐一个起点?我应该读什么?对于初学者/中级程序员来说,尝试实现这一目标的最简单方法是什么?
目前,我希望它能够将文本从一台机器发送到另一台机器。到目前为止我对java中与网络相关的任何东西都不熟悉。我会使用服务器还是直接在两台机器之间连接?
任何人在这件事上的任何指示/方向或建议都会非常有帮助!
I'm currently working on trying to create a very basic bare bones instant messenger with Java.
I'm at a bit of a loss where to begin, was wondering if anyone here could reccommend a starting point? What I should read? What would be the easiest way for a beginner/intermediate programmer to try and achieve this?
Currently, I'll I'd want it to be able to do is to send text to one machine to another. I am so far unfamiliar with anything network related in java. Would I use a server or just direct connect between two machines?
Any pointers/direction or advice anyone has in this matter would be very helpful!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先查看官方资源Socket编程,关于编写Client的文章/Server Pair 应该为您提供创建即时通讯工具所需的信息。
Firstly check out the official resource for Socket programming, the article on writing a Client/Server Pair should provide you with what you need to know to create a instant messenger.
嗯,我重点关注你的第二个问题。
如果您正在为局域网构建此程序并且打算使用套接字编程,则需要找到机器的确切 IP 地址。如果你不知道 IP 地址(我的意思是如果你不希望程序在运行之前知道 IP 地址),那么你可以 ping 本地 IP 地址,直到找到一些对等点。
一些 p2p 应用程序使用服务器作为 ip 匹配器。这意味着服务器具有 IP 地址表,使所有用户都可以使用这些服务器发送/接收数据。但如果你刚刚开始使用这个项目的网络,我认为不要使用服务器。
最后,大家可以看一下我自己的一个项目。这是一个简单的并行文档准备程序,内部有一个聊天模块。它是用 C# 开发的。它需要无线自组织网络才能运行。链接:http://code.google.com/p/parallel-docs/
Well, I am focusing the second question of yours.
If you're building this program for your local area network and if you're intended to use socket programming, you need to find the exact ip address of the machine. If you don't know the ip address ( I mean if you don't want the program to know ip address before you run it ) ,then you can ping local ip addresses until you find some peers.
Some of the p2p applications use servers as the ip matchers. This means that the servers have ip address tables which make all of the users send/receive data by using these servers. But if you just started on networking with this project, I think don't use server.
Lastly, you can take a look at a project of my own. It's a simple parallel document preparation program with a chat module inside it. It's developed in C#. It needs wireless ad hoc network to run. Link : http://code.google.com/p/parallel-docs/
我认为这种类型的项目永远不会成为初学者项目。我绝对不会阻止你尝试,我认为你应该这样做。我总是对这样的事情感到困惑,但我查阅并提出问题,通常最终会学到一些东西。我的建议是,无论程序多么简单,都从一些类图开始,如果没有别的办法,只是在进入代码之前进行组织。例如,您知道您立即需要一个用户帐户对象,并且您知道您需要该对象的某些属性(用户名、密码等),我封装了所有内容,因此您需要方法来获取和设置这些字段等等。我发现,通过这样做,即使我没有创建完整、正确的 UML 图,也能把简单的东西排除在外,如果没有其他办法的话,首先进行一些组织,让我能够专注于更复杂的逻辑和我可能还没有关注的事情知道如何实施。
I don't think this type of project is ever going to be a beginner project. I'm absolutely not discouraging you to try it, I think you should. I'm always in over my head with stuff like this but I look it up and ask questions and usually end up learning something. My advice would be no matter how simple of a program it is, start with some Class Diagrams, if nothing else just to get organized before jumping into the code. For example you know you you'll need a user account object right off the bat and you know you'll need certain attributes for that object (username, password, etc.), I encapsulate everything so then you would need methods to get and set these fields and so on. I've found that by doing that even if I don't create complete proper UML diagrams getting the easy stuff out of the way and if somewhat organized first if nothing else frees me to focus on the more complex logic and things I may not yet know how to implement.