473,834 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

query to website

35 New Member
i am writing an client application that connects to the server and then sends data to server.
but, the problem is that i get a java.net.Connec tException: Connection refused error.
The code i have written is :
Expand|Select|Wrap|Line Numbers
  1. //package bdn;
  2. /*  The java.net package contains the basics needed for network operations. */
  3. import java.net.*;
  4. /* The java.io package contains the basics needed for IO operations. */
  5. import java.io.*;
  6. /** The SocketClient class is a simple example of a TCP/IP Socket Client.
  7.  *
  8.  */
  9.  
  10. public class SocketClient {
  11.      public static void main(String[] args) {
  12.         /** Define a host server */
  13.         //find the ip address by ping cmd in unix
  14.         String host = "211.65.63.147";
  15.         /** Define a port */
  16.         int port = 8080;
  17.  
  18.         StringBuffer instr = new StringBuffer();
  19.         String TimeStamp;
  20.         System.out.println("SocketClient initialized");
  21.  
  22.         try {
  23.           /** Obtain an address object of the server */
  24.           InetAddress address = InetAddress.getByName(host);
  25.           /** Establish a socket connetion */
  26.           Socket connection = new Socket(address, port);
  27.           /** Instantiate a BufferedOutputStream object */
  28.           BufferedOutputStream bos = new BufferedOutputStream(connection.
  29.               getOutputStream());
  30.  
  31.           /** Instantiate an OutputStreamWriter object with the optional character
  32.            * encoding.
  33.            */
  34.           OutputStreamWriter osw = new OutputStreamWriter(bos, "US-ASCII");
  35.  
  36.         }
  37.         catch (Exception g) {
  38.         System.out.println("Exception: " + g);
  39.             }
  40.  
  41.     }
  42.  
  43.  
  44. }
  45.  
please let me know wat could be the problem.
Jan 24 '09
13 3038
JosAH
11,448 Recognized Expert MVP
@chaarmann
That's not how Java memory allocation works; Java keeps a simple heap which is a contiguous chunk of memory; all objects are allocated next to each other until all memory is used; either another chunk of memory is allocated from the OS or the garbage collector is fired up.

This scenario makes memory allocation as cheap as can be and all sorts of object pooling etc. merely hinder than help the garbage collector nowadays. (google for "Java garbage collection" and you'll find the discussions).

The garbage collector applies a "generation scavenging" strategy, i.e. lots of objects in Java just live for a short while (e.g. local objects) and only some of them survive the first (small) collection phases. They are copied to an 'eden' space where they won't be affected by those small garbage collection phases. Only when all else fails (maximum heap size has been reached and no more memory could be collected) a full garbage collection is started that also checks the 'eden' space.

C and C++ use a much more naive approach and they don't move the allocated chunks of memory around so they have to maintain some form of a linked list of free/allocated memory. That can cause fragmentation but Java doesn't suffer from it.

Several containers (StringBuilder, ArrayList etc.) anticipate on the allocation of more memory by allocating (a bit) more memory than is strictly needed so they can use that memory in the near future. Strings don't do that, they're immutable and catenating Strings over and over again is a very inefficient operation.

As a rule of thumb: don't try to help the garbage collector; it knows how to do its job. Memory allocation is as fast as can be; constructors simply initialize/modify this already allocated memory.

kind regards,

Jos
Jan 29 '09 #11
chaarmann
785 Recognized Expert Contributor
And the String data itself? Isn't it copied over to the new memory location every time? Or does String use an internal array of allocated memory chunks, so that a string must not be linear in memory?

Jos, so what do you think in this case, how much times is it faster? On a scale from "not measurable percentage" to "many times"?
(If I write "new StringBuilder(1 0000)" instead of "new StringBuilder() " for an total average of 7000 characters loaded which are added line by line ?)
Jan 29 '09 #12
JosAH
11,448 Recognized Expert MVP
@chaarmann
Most of the time the char buffers are copied over. An exception to the rule is the substring() method; the newly created String shares the buffer with the original String. If you read the source code of that class (see the src.zip file in your JDK installation) you'll see that the String class plays a few tricks with the StringBuffer class as well ...

@chaarmann
Of course preallocating a large enough buffer will be faster than simply incrementing the buffer over and over again; you don't have to copy the data in the buffer over and over again. otoh, 7000 characters isn't that much ...

kind regards,

Jos
Jan 29 '09 #13
eternalLearner
35 New Member
hi, thanks for all the inputs
I did as suggested, but the code still doesnot work.
Am I posting the query in incorrect format ??
the site is up now,
Feb 28 '09 #14

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

Similar topics

4
2279
by: leegold2 | last post by:
Let's I do a mysql query and then I do a, for( $i = 1; $row = mysql_fetch_array($result); $i++ ) {...} and it gives me this: PageID Title URL Description 1 lee's gogle1.com This is lee's website. 1 lee's gogle2.com This is lee's website. 2 Jon's yaho1.com This is Jon's website. 2 Jon's yaho2.com This is Jon's website.
14
3238
by: Bruce W...1 | last post by:
I do a query to MySQL using PHP. Well actually I do too many of them which is the problem, it's too slow. I think maybe an inner join or something would be better but I can't figure this out. The web page on which the data is displayed has a list of countries. Each country has a label heading under which websites are listed that have information on that country. Any given website may appear many times (under different countries) if it...
1
1374
by: Lukelrc | last post by:
Hi. I have a table (websitehits) which holds statistics about websites. This table has a date field (datecounted). What I need is to create a query which returns a list of dates between two date ranges (say a year ago from today and a year from now) which only shows dates that haven't been used in the websitehits table for a given website. For example if my table contains something like:
2
1458
by: tdmailbox | last post by:
I have a database with three tables tbl_listings - listings of houses on for sale tbl_intersted - table which tracks if a user is interested in the listing, it has two columns mls(the key for tbl_listings) and user(user login) tbl_review - table which trackes if a user has reviewed the listing. Like tbl_interested it has two columns (the key for tbl_listings) and user(user login)
3
2840
by: MX1 | last post by:
Here's a type of query I'm always having trouble with. There are 4 fields in a web access log table. User | Date | Time | Destination I want to show all the instances of a user hitting a particular web site, but I only want a single entry to represent that visit (not the 10 or 15 that represent every graphic that was obtained from the page as is typical with imported web logs).
4
1973
by: Wim Verhavert | last post by:
Hi all, For gathering certain information in building my database, I'm depending on the things I found on the web, especially one website (let's call it www.mywebsite.com). Is there a way to query this site (it has fill in boxes on the page and a search button) depending on values in my form and getting the results back in my form? This (general) question is keeping me out of my sleep for weeks now.... Any tip is appreciated....
9
1736
by: Jeff Gardner | last post by:
Greetings: I have an UPDATE query (php 5.1.6/mysql 5.0.24a on apache 2.2) that appears to execute with no errors (php,mysql, or apache) but the data in the "UPDATED" table doesn't change. I've checked privileges for connecting account and that isn't an issue. Maybe it's my query: $editO = " UPDATE organization SET
9
4027
by: JJM0926 | last post by:
I'm trying to create a running totals query in access 97. I have followed the directions on how to do it from Microsofts website article id 138911. I took their code they had and replaced it with my fields. When I try to run it I get #errors in my RunTot column. I'm kinda new to this. Not sure if maybe I mistyped something wrong or is there a better way to do this? I have pasted the code. Any help would be greatly appreciated....
8
2452
siridyal
by: siridyal | last post by:
I have a wholesale website that i'm working on that shows hundreds of items that are updated from time to time. These items are kept in a mysql database with several tables. I want to let the the customer browse (from a dynamically created drop down list - which i've done) the items by furniture class, and then have the query results limited to 26 items per page, in two columns using DIVs. The CSS for the DIVs is taken care of, as is the...
3
4836
by: DigitalWallfare | last post by:
Hi all, This is my first post here, but i've lurked for a while. I'm working on a website but have come across a major stumbling block in the code: I've managed to structure the search query but have 2 problems: I dont know how to code the results into the table, and make the table repeat itself 5 times per page (and recognise it needs a new page)
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10500
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10543
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10213
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.