如何使用套接字和创建/修改txt文件在Java中建立连接? [英] How do I make a connection in Java using socket and creating/modifing a txt file?

查看:76
本文介绍了如何使用套接字和创建/修改txt文件在Java中建立连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!



我正在研究一个java项目,我想使用套接字建立连接,但我也想创建一个txt文件 - 我可以要么手动创建,要么在我的项目中创建 - 我可以检查是否符合我的一些要求 - 假设它长50个字符或只有数字等 - 我可以在运行项目时进行修改。



我读了这两篇文章:



Hello!

I am working on a java project and I want to make a connection using sockets but I also want to create a txt file-which I can either create manually or create in my project- that I can check if goes along with some of my requirements-let's say it's 50 characters long or has only numbers etc- and I can modify as I run my project.

I read these two articles:

Using Sockets in Java - Server



[ ^ ]



在Java中使用套接字 - 客户端 [ ^ ]



我有一些问题。

我把我的要求放在客户端部分,对吗?

服务器回答让我们说​​是为真,否为假?



我的头脑中有这个概念吗?如果我错了,你可以纠正我的整个想法吗?

有没有人有任何阅读材料或教程可以帮助我或一些建议?



谢谢!


[^]

Using Sockets in Java - Client[^]

And I have some questions.
I put my "requirements" in the client part,right?
And the server answers let's say "yes" for true and "no" for false?

Do I have the concept in my head straight?Can you correct me about the whole idea if I am wrong?
Does anyone have any reading material or tutorials that can help me or some suggestions?

Thank you!

推荐答案

把它想象成一个电话。您(客户端)向服务提供商(服务器)发出呼叫。建立连接后,您会询问服务提供商的问题并提供答案。有时服务提供商会提出问题,客户会提供答案。唯一的问题是你说同一种语言,并了解提供什么信息以及提供什么形式。



典型的序列如下:

Think of it like a telephone call. You, the client, make a call to a service provider, the server. Once you have established the connection you ask questions of the service provider and it provides answers. And sometimes the service provider will ask questions and the client will provide the answers. The only issue is that you speak the same language and understand what information is to be provided and in what form.

A typical sequence would be something like:
Client: connect to server
Server sends message: Please enter your userid:
Client sends message: user01
Server sends message: Please enter your password:
Client sends message: passwd01
Server verifies userid and password
    If valid
        Send message: welcome to the server, please enter your command.
    Else
        Send message: invalid credentials, access denied.
        Server closes connection.
    Endif

... etc.





目前尚不清楚此文本文件的位置存在于服务器或客户端上,因此您需要明确说明。无论是哪个,该应用程序都可以通过套接字传递的信息轻松创建文件。



[edit]

< a href =http://www.davidreilly.com/java/java_network_programming/> Java网络编程常见问题解答 [ ^ ]

课程:所有关于套接字 [ ^ ]

[/ edit]



It is not clear where this text file will exist, on the server or the client, so you need to make that clear. Whichever it is, it is easy for that application piece to create the file from information passed through the socket.

[edit]
Java Network Programming FAQ[^]
Lesson: All About Sockets[^]
[/edit]


这篇关于如何使用套接字和创建/修改txt文件在Java中建立连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆