473,382 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

need help with my senior project

hi everybody

i am nwebie in this forum but i think it is useful for me and the member are helpful

my project is about connecting client with the server to start exchanging messages between them.

to be more clear we process this purpose we serve this to the student in the university. how??
student will send a message that contains his name,id and request by format the server want such as zaina-20024008-grade.
the grade is the request and it will be different from one to another becouse it may be subject,pass credit or remain credits an so on. and then click send

when the message recievd to the server the server will superate the message to keep name , id and grade in its location to use it later. then it will access to the database with the name and id it got and start to get the request result and then send it back to the client and ask to the client if he need to get othe info or terminate

i thought to communicate the client with the server by socket connection " stream socket" and i have just finshed the code for one side which is for the server and still working to the client but i have a question occured in my mind and it may stupid question to you

since we diclare the port number in both client and server for listening to connect and declare the ip number in the client which is the local host name, is must the socket connect to network to available access and connect? in another meaning do i need to use modem to be the server connect to the internet becouse since we declare the host name"ip" we need network layer
does it??

i need you help please and sorry for my weakness language but i hope you understand what i want and looking for

i post the code here and note that the double quotation thais for the database i didnt fill still
Expand|Select|Wrap|Line Numbers
  1. package test;
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  7. import java.net.ServerSocket;
  8. import java.net.Socket;
  10. import java.sql.Connection;
  11. import java.sql.DriverManager;
  12. import java.sql.ResultSet;
  13. import java.sql.SQLException;
  14. import java.sql.Statement;
  17. public class PcServer extends Thread {
  18.     // declare unbound server socket
  19.     private ServerSocket ServS =null ;
  20.     //declare unconnected client socket
  21.     private Socket ClientConnection = null;
  22.     // input stream from client
  23.     private ObjectInputStream IS;
  24.     //output stream to client
  25.     private ObjectOutputStream OS;
  28.     //CONSTRUCTOR
  29.     public PcServer (Socket ClientSocket){
  30.         ClientConnection = ClientSocket;
  31.     }
  33.     public PcServer() {}
  36.     // set up run server
  37.     public void runServer(){
  38.         try //creat server socket
  39.         { ServS = new ServerSocket (3131);//3131 is the port number      
  40.     }
  41.     catch (IOException e) {
  42.         System.err.println("Could not listen on port:3131");
  43.         System.exit(-1);
  44.     } 
  45.         boolean listening = true;
  46.         while (listening)
  47.         { try
  48.           { ClientConnection = ServS.accept();//allow server to accept connection from client
  50.             //open input stream from the socket connection to read the data from the client
  51.             IS=new ObjectInputStream(ClientConnection.getInputStream());
  53.             //open data out stream from the socket connection to write data to the client
  54.             OS=new ObjectOutputStream (ClientConnection.getOutputStream());
  56.             //start the process(sending and recieving data) from/to client
  57.              starExchange();
  58.           }
  59.           catch (Exception Ex){
  60.               Ex.printStackTrace();
  61.           }
  62.           try // terminate all connection and close stream gate
  63.           { OS.close();
  64.             IS.close();
  65.             ClientConnection.close();}
  66.           catch (Exception ex)
  67.           { ex.printStackTrace();}
  69.         }
  70.     }
  71.         //start the process of the program
  72.         public void starExchange() throws Exception{
  73.             String msg =(String)IS.readObject();//read msg coming from client
  74.             //EON=End Of Name
  75.             int EON = msg.indexOf('-');
  76.             //message getting from client = name-id-request
  77.             // extract the name from the msg
  78.             String name = msg.substring(0, EON);
  79.             //extract id from the msg
  80.             long ID = Long.parseLong(msg.substring(EON+1, EON+9));
  82.             //extract request from the msg
  83.             String Request = msg.substring(EON+10, msg.length());
  84.             //JDBC driver name and database URL
  85.             final String JDBC_DRIVER ="";
  86.             final String DATABASE_URL="";
  88.             //manage database connection
  89.             Connection DBconnection = null;
  90.             Statement DBstatement = null; // query statement
  92.             //connect to the student database and query database
  93.             try {
  94.                 // load database driver class
  95.                 Class.forName (JDBC_DRIVER);
  96.                 //establish connection to database
  97.                 DBconnection = DriverManager.getConnection (DATABASE_URL,"","");
  98.                 //create statement for quering database
  99.                 DBstatement = DBconnection.createStatement();
  100.                  request(Request,name,ID, DBconnection);
  101.             }
  102.             catch (SQLException sqlException){
  103.                 sqlException.printStackTrace();
  104.             }
  105.            finally // close DBstatement and DBconnction
  106.            {
  107.                try 
  108.                { DBstatement.close();
  109.                  DBconnection.close();
  110.            }
  111.                catch (Exception exception)
  112.                { exception.printStackTrace();
  113.         }
  114.            }
  115.         }
  117.         public void request ( String R,String N,long id, Connection connection) throws Exception
  118.         {
  119.           //query database
  120.             Statement st = connection.createStatement();
  121.             ResultSet resultset = st.executeQuery("SELECT"+R+"FROM Student-Table WHERE ID="
  122.                     +id+"AND NAME="+N);//select the result according to the name and id of student
  123.                                        // return the result according to the request
  124.             OS.writeObject("NAME:"+N+"-ID:"+id+"-"+R+"is"+resultset+"/n Do you need to get othe information?/n" +
  126.                     "send (Y/N) with your request  if Y");//SEND RESULT OF STUDENT REQUEST
  127.             String newR=(String) IS.readObject();//READ THE STUDENT RESPOSE
  131.             if (newR.charAt(0)=='y'||newR.charAt(0)=='Y')
  132.             { // extract client request
  133.                 String newReq=newR.substring(2,newR.length());
  134.                 //recursive function...check other request
  135.                 request(newReq,N,id, connection);
  136.             }
  138.         }
  139.         }
Feb 24 '08 #1
6 2959
2,364 Expert 2GB
I think you English is fine...

Why aren't you using an app server name in the place of your local host name?
Dec 12 '08 #2
13,262 8TB
Not sure what an application server name would have to do with all this.
@Dokoll : Could you please check your PMs and respond appropriately?
Dec 12 '08 #3
2,364 Expert 2GB
My bad, you're right r035198x, will read carefully. Here's a bit of info I found on the site, perhaps that'll steer OP in the right direction:

Lesson 1: Socket Communications
Jan 6 '09 #4
11,448 Expert 8TB
That online book was written in 1999; it teaches you old Java; I don't think that posting (almost) random Google results here whithout knowing what the subject is all about is a good idea. Please don't do that anymore; there is an up to date link available to the API documentation and the Tutorials in the first article in this group.

kind regards,

Jos (moderator)
Jan 6 '09 #5
237 100+
i will respond to what i understood.
don't include a server name in the program, include its ip address, to make sure that it doesn't change later, set the server to a static IP address.

A question, are you trying to create a chatting service? if so, use the Socket class and the ServerSocket class to implement your service.

and read this tutorial, i think it may help.
Lesson 1: Socket Communications

kind regards
Jan 6 '09 #6
11,448 Expert 8TB
Read my reply #5.

kind regards,

Jan 7 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Slash | last post by:
Hello everyone I'm looking for seminar topics (and project ideas too) for my final year in Computer Engineering. I'm considering doing something on C++/Linux, considering that I love it so much...
by: Steve Jorgensen | last post by:
Hi all, I'm working on a project through a consulting company, and I'm writing some database code for use in another programmer's project in Excel/VBA. The other programmer is working through...
by: Brett Baisley | last post by:
At school, we do all of our coding in emacs, but I am trying to get the example apps working at home using Visual C++.net. In the example, there are 4 .cpp files (canvas.cpp, main.cpp,...
by: Martin | last post by:
Hello, We are in the process of putting together an A class C++ Development team(ecommerce / billing applications) for a project in the Bay Area. Reqt. details: ReqId : Req-3911 - C++ Senior...
by: xxbabysue123xx | last post by:
Heres the problem: Create a class Student with instance data name, studentNumber, class (where class is a String containing one of the following: “Freshman”, “Sophomore”, “Junior”, “Senior”. ...
by: squishy | last post by:
I tried to hire programmers to do some stuff, but cannot find reliable, intelligent C++ Gurus (at Guru or RentACoder at least). So I am stuck learning C++ and doing the jobs myself. I would...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.