Welcome to Dream.In.Code
Become a Java Expert!

Join 150,375 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,683 people online right now. Registration is fast and FREE... Join Now!




Sending and receiving two different variables from a client to a serve

 
Reply to this topicStart new topic

Sending and receiving two different variables from a client to a serve

michael351
4 Feb, 2008 - 08:59 PM
Post #1

New D.I.C Head
*

Joined: 29 Jan, 2008
Posts: 12

Does anyone know how i can make my server send two variables to the client, I'v got one working, I just can't get two or more,

The error i get is

D:\Documents and Settings\KfeilatiM\Desktop\Final Print Outs Fri AfterNoon\Edited\LibraryServer.java:48: ';' expected
private String getPrice()

hear is my code so far.
CODE

import java.io.*;
import java.net.*;
import javax.swing.JOptionPane;
public class LibraryServer
{
        String bookStr = JOptionPane.showInputDialog(null,"Enter Book Name:");
        String priceStr = JOptionPane.showInputDialog(null,"Enter Book Price in whole:");

        int price = Integer.parseInt(priceStr);
        String Book;


    String message[] = { " The Book Name you are enquireing about is " ,(Book) + (priceStr)
                          };

    public void go()
    {
        try
        {
            System.out.println("Started server....");
            System.out.println("The Book name is "+(bookStr)+" and the cost for that is "+(priceStr));
            System.out.println("Creating a server socket....");
            ServerSocket serverSocket = new ServerSocket(4242);
            System.out.println("Server Waiting for Librady Request Client to Contact");

            while(true)
            {
                Socket sock = serverSocket.accept();
                PrintWriter writer = new PrintWriter(sock.getOutputStream());
                writer.println(price);
                writer.println(Book);
                writer.close();
                System.out.println(price);
                System.out.println(Book);


            }
        }




        catch(IOException ex)
        {
            ex.printStackTrace();
        }
    }
    private String getPrice()
    private String getBook()



    {
        return priceStr;
        return bookStr;
    }
    public static void main(String args[])
    {
        LibraryServer server = new LibraryServer();
        server.go();
    }
}

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Sending And Receiving Two Different Variables From A Client To A Serve
4 Feb, 2008 - 11:32 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,327



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
These getter methods need to be two separate methods.
CODE

    private String getPrice()
    private String getBook()



    {
        return priceStr;
        return bookStr;
    }


Should be:
CODE

    private String getPrice()
    {
        return priceStr;
     }

    private String getBook()
    {        
        return bookStr;
    }

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:56PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month