• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URL and Severs(very Urgent)

 
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
First of all, I want to know that what kind of server we can use for URL means Application server or web server or both?
SEcondly, I want to know that what kind of data we can get from server like jpg,text,file and finally in which form means always we can get any data in HTML form from server to client?
Please let me know
Thanks
ANgela
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
web server is required for URL.
this web server should have to provide a service on a perticuler
port
&
our client would get connected by typing a url in address
the formate would be
http:\\<<service provider name>> ort\<<client program>>
here is some client program
//________________
import java.net.*;
import java.io.*;
import java.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ClientApplet extends Applet implements Runnable{
private TextArea theTextArea=null;
private TextField theTextField=null;
private Thread thread=null;
private ServerConnection connection=null;
public void init(){
try{
//System.out.println(connection.getNextMessage());
theTextArea =new TextArea("Main Chat Room....",10,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
theTextField=new TextField();
theTextField.setSize(100,25);
theTextField.requestFocus();
theTextArea.setEditable(false);
this.setLayout(new BorderLayout(2,3));
this.add(theTextField,BorderLayout.SOUTH);
this.add(theTextArea,BorderLayout.NORTH);
this.setVisible(true);
connection=new ServerConnection("192.168.0.249",6006);
theTextField.addKeyListener(new KeyListener(){
public void keyPressed(java.awt.event.KeyEvent A) {
if (A.getKeyCode()==A.VK_ENTER) {
if (!theTextField.getText().equals("")) {
connection.broadcastMessage(theTextField.getText());
//theTextArea.append(connection.getNextMessage());
theTextField.setText("");
}//innet IF
}//outer IF
if (A.getKeyCode()==A.VK_0){
theTextArea.append(connection.getNextMessage());
}
}
public void keyReleased(java.awt.event.KeyEvent A) {
}
public void keyTyped(java.awt.event.KeyEvent A) {
}
});
}
catch(Exception exp){
}
}
public void start(){
//connection.getNextMessage();
// if(thread==null){
thread=new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
// }
// else
// thread.start();
}
public void run() {/*
while ( thread==Thread.currentThread() ) {
String line = connection.getNextMessage();
if (!line.equals(null)) {
//line=line.substring(this.SERVER_MSG_PREFIX.length());
theTextArea.append(line+"\n");
//System.out.println(line);
}
}//END-WHILE
*/}
}
 
maateen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
web server is required for URL.
this web server should have to provide a service on a perticuler
port
&
our client would get connected by typing a url in address
the formate would be
http:\\"<<service provider name>>":"port"\"<<client program>>"
here is some client program
//________________
import java.net.*;
import java.io.*;
import java.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ClientApplet extends Applet implements Runnable{
private TextArea theTextArea=null;
private TextField theTextField=null;
private Thread thread=null;
private ServerConnection connection=null;
public void init(){
try{
//System.out.println(connection.getNextMessage());
theTextArea =new TextArea("Main Chat Room....",10,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
theTextField=new TextField();
theTextField.setSize(100,25);
theTextField.requestFocus();
theTextArea.setEditable(false);
this.setLayout(new BorderLayout(2,3));
this.add(theTextField,BorderLayout.SOUTH);
this.add(theTextArea,BorderLayout.NORTH);
this.setVisible(true);
connection=new ServerConnection("192.168.0.249",6006);
theTextField.addKeyListener(new KeyListener(){
public void keyPressed(java.awt.event.KeyEvent A) {
if (A.getKeyCode()==A.VK_ENTER) {
if (!theTextField.getText().equals("")) {
connection.broadcastMessage(theTextField.getText());
//theTextArea.append(connection.getNextMessage());
theTextField.setText("");
}//innet IF
}//outer IF
if (A.getKeyCode()==A.VK_0){
theTextArea.append(connection.getNextMessage());
}
}
public void keyReleased(java.awt.event.KeyEvent A) {
}
public void keyTyped(java.awt.event.KeyEvent A) {
}
});
}
catch(Exception exp){
}
}
public void start(){
//connection.getNextMessage();
// if(thread==null){
thread=new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
// }
// else
// thread.start();
}
public void run() {/*
while ( thread==Thread.currentThread() ) {
String line = connection.getNextMessage();
if (!line.equals(null)) {
//line=line.substring(this.SERVER_MSG_PREFIX.length());
theTextArea.append(line+"\n");
//System.out.println(line);
}
}//END-WHILE
*/}
}
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maateen,
Thanks a lot for ur reply
In following program u have used URL methods?
Please let me know...
Thanks

Originally posted by maateen:
web server is required for URL.
this web server should have to provide a service on a perticuler
port
&
our client would get connected by typing a url in address
the formate would be
http:\\<<service provider name>> ort\<<client program>>
here is some client program
//________________
import java.net.*;
import java.io.*;
import java.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ClientApplet extends Applet implements Runnable{
private TextArea theTextArea=null;
private TextField theTextField=null;
private Thread thread=null;
private ServerConnection connection=null;
public void init(){
try{
//System.out.println(connection.getNextMessage());
theTextArea =new TextArea("Main Chat Room....",10,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
theTextField=new TextField();
theTextField.setSize(100,25);
theTextField.requestFocus();
theTextArea.setEditable(false);
this.setLayout(new BorderLayout(2,3));
this.add(theTextField,BorderLayout.SOUTH);
this.add(theTextArea,BorderLayout.NORTH);
this.setVisible(true);
connection=new ServerConnection("192.168.0.249",6006);
theTextField.addKeyListener(new KeyListener(){
public void keyPressed(java.awt.event.KeyEvent A) {
if (A.getKeyCode()==A.VK_ENTER) {
if (!theTextField.getText().equals("")) {
connection.broadcastMessage(theTextField.getText());
//theTextArea.append(connection.getNextMessage());
theTextField.setText("");
}//innet IF
}//outer IF
if (A.getKeyCode()==A.VK_0){
theTextArea.append(connection.getNextMessage());
}
}
public void keyReleased(java.awt.event.KeyEvent A) {
}
public void keyTyped(java.awt.event.KeyEvent A) {
}
});
}
catch(Exception exp){
}
}
public void start(){
//connection.getNextMessage();
// if(thread==null){
thread=new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
// }
// else
// thread.start();
}
public void run() {/*
while ( thread==Thread.currentThread() ) {
String line = connection.getNextMessage();
if (!line.equals(null)) {
//line=line.substring(this.SERVER_MSG_PREFIX.length());
theTextArea.append(line+"\n");
//System.out.println(line);
}
}//END-WHILE
*/}
}


 
maateen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have used an object of serverconnection class
this is class which constructs a URL with that server....
i m sending the code for that class
it may help U..
//_________________________________
import java.io.*;
import java.net.*;
import java.util.*;
public class ServerConnection {
private static int uniqNum = 0;
private static final String SERVER_MSG_PREFIX = "SERVER";
private static final String CLIENT_MSG_PREFIX = "GETNEXTMSG";
private static final String ECHO = "ECHO";
private URL baseUrl;
public ServerConnection(String host, int port){
try {
System.out.println("stating to get connected");
baseUrl = new URL("http://" + host + ":" + port + "/" );
System.out.println(baseUrl);
} catch (MalformedURLException e) {
System.out.println ("Error forming baseURL");
}
}
public String getNextMessage(){
//Runtime.getRuntime().exec("");
String tempString=null;
try{
URL u=new URL(this.baseUrl,ServerConnection.encode(ServerConnection.CLIENT_MSG_PREFIX+ServerConnection.uniqNum++));
//System.out.println("GETNEXTMESSAGE"+u);
BufferedReader read=new BufferedReader(new InputStreamReader(u.openConnection().getInputStream()));
tempString = read.readLine();
read.close();
}
catch(java.io.IOException ioexp){
System.out.println(ioexp.toString());
}
return tempString;
}
public void broadcastMessage(String message){
String encodedMessage=ServerConnection.encode(ServerConnection.ECHO+message);
try{
URL u=new URL(baseUrl,encodedMessage);
u.openConnection().getInputStream().close();
System.out.println(u);
}
catch(java.net.MalformedURLException murlexp){
System.out.println(murlexp.toString());
}
catch(java.io.IOException ioexp){
System.out.println(ioexp.toString());
}
}
static String encode (String str) {
StringBuffer buf = new StringBuffer();
for (int i = 0, len = str.length() ; i < len ; i++) {<br /> char c = str.charAt(i);<br /> if (((c >= 'a') && (c <= 'z')) | | ((c >= 'A') && (c <= 'Z')) | |<br /> ((c >= '0') && (c <= '9'))) {<br /> buf.append(c);<br /> } else {<br /> buf.append('%');<br /> buf.append(Character.forDigit((c >> 4) & 0xF, 16));
buf.append(Character.forDigit((c >> 0) & 0xF, 16));
}
}
return buf.toString ();
}
}
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maaten,
I really appreciate your help. My confusion is that if we used URL method we have to make only one program, if yes where we have to run means on client machine or server machine. (I know in socket we can make two one client program and another server program and we can run on appropriate machine) Please i want to be more clear...

Thanks a lot again
Angela
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi maateem.
what is wrong with this program:
import java.net.*;
import java.io.*;
public class MyTest1 {
URL url;
BufferedReader in;
PrintWriter out;
String s;
public MyTest1()
{
try
{
URL url = new URL("http://10.3.158.222:8080");
}
catch(MalformedURLException e)
{
System.out.println("Connection failed");
}
try
{
URLConnection uc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
BufferedReader kbdInput = new BufferedReader(new InputStreamReader(System.in));
String inputLine;
while (true){
inputLine = kbdInput.readLine();
if(inputLine == null) break;
out.println(inputLine);
System.out.println(in.readLine());
}
}
catch(IOException e)
{
System.out.println("Here is an error" + e.getMessage());
}
}
public static void main (String[] args){
MyTest1 t = new MyTest1();
}
}

Thanks in advance,
Angela

 
reply
    Bookmark Topic Watch Topic
  • New Topic