Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
Using Sockets in Java - Server

[^]

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!
Posted

1 solution

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.


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]
 
Share this answer
 
v2
Comments
HopefullyCoder 19-May-14 9:16am    
The telephone call example was really helpful,thank you!The text file will be on the client.
About the "Server verifies userid and password" part,the if statement will be on the client?And the valid or invalid message will be from the server,right?
Richard MacCutchan 19-May-14 11:24am    
OK, so the client can manage the text fille via Basic I/O as required, even using some of the information retrurned from the server.

Yes, the server verifies the logon credentials and sends a message back to the client to indicate success or failure. Essentially a server is a passive application that responds to requests from the client; and an initial connection is effectively a request. Also remember that if this is a setup for your own use, you can decide on the format of requests and responses between the two ends.

I've added a couple more links in my solution above to further information about networking in Java.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900