Results 1 to 20 of 22
Thread: line
- 10-05-2010, 01:56 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 11
- Rep Power
- 0
- 10-06-2010, 10:02 AM #2
- 10-06-2010, 04:29 PM #3
Member
- Join Date
- Aug 2010
- Posts
- 11
- Rep Power
- 0
Hi
Just write the word in two lines.
(Write the word in 2 lines in client which word comes from server)
Thx
- 10-06-2010, 04:59 PM #4
Can you show what the output would look like? For example if your program received the word: programming
How do you want it to be written?
line1: ???
line2: ???
- 10-07-2010, 03:46 AM #5
Member
- Join Date
- Aug 2010
- Posts
- 11
- Rep Power
- 0
Hi
programmingprogrammingprogrammingprogrammingprogra mmingprogrammingprogrammingprogrammingprogrammingp rogrammingprogrammingprogrammingprogrammingprogram ming
programmingprogrammingprogrammingprogrammingprogra mmingprogrammingprogrammingprogrammingprogrammingp rogrammingprogrammingprogrammingprogrammingprogram ming
just in 2 line write programming (like chargen2)
thx
- 10-07-2010, 11:27 AM #6
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
i think you have to copy your code at here
- 10-07-2010, 01:49 PM #7
What you show as the desired output is the one word repeated n times on each line.
To get that use a nested loop. On the inner loop use print() for the n times you want the word repeated. after the inner loop use println() to move to the next line. The outer loop for the number of lines
- 10-07-2010, 06:54 PM #8
Member
- Join Date
- Aug 2010
- Posts
- 11
- Rep Power
- 0
Hi
Thanks
This code:
for (int j = 0; j<20; j++)
System.out.print(sentence);
Suppose to write my sentence in sequence 20 times? Am I right?
But it just type two time, in two lines; For example if my server received the word, programming. written:
Programming
Programming
- 10-07-2010, 07:11 PM #9
I don't think the code you posted would output the two lines you show.
Are you sure that is the code that is executing?
Change it to: System.out.print("s=" + sentence + "<");
to be sure that it is executing.
- 10-08-2010, 04:19 AM #10
Member
- Join Date
- Aug 2010
- Posts
- 11
- Rep Power
- 0
Hi, Thanks but still has the same problem
The code of my client is:
package linesclient;
import java.net.*;
import java.io.*;
/**
* @author Shima
*/
public class Main {
public static void main(String[] args) throws Exception {
byte[] receivedata = new byte[512];
byte[] senddata = new byte[512];
DatagramSocket clientsoket = new DatagramSocket();
InetAddress ipaddress = InetAddress.getByName("localhost");
BufferedReader bufferreaderuser = new BufferedReader(new InputStreamReader(System.in));
String str = bufferreaderuser.readLine();
senddata = str.getBytes();
DatagramPacket sendpacket= new DatagramPacket(senddata, senddata.length, ipaddress,9876);
clientsoket.send(sendpacket);
DatagramPacket recievepaket = new DatagramPacket(receivedata, receivedata.length);
clientsoket.receive(recievepaket);
String sentence= new String(recievepaket.getData());
for (int j = 0; j<5; j++){
System.out.print("s="+sentence+"<");
}
clientsoket.close();
}
}
---------------------
and server code is:
package lines;
import java.net.*;
//import java.io.*;
/**
* server
* @author Shima
*/
public class Main {
public static void main(String[] args) throws Exception {
byte[] recievedata = new byte[512];
byte[] senddata = new byte[512];
DatagramSocket serversoket = new DatagramSocket(9876);
while (true){
DatagramPacket recievepacket = new DatagramPacket(recievedata,recievedata.length);
serversoket.receive(recievepacket);
InetAddress ipaddress= recievepacket.getAddress();
int port= recievepacket.getPort();
senddata = recievepacket.getData();
DatagramPacket sendpacket = new DatagramPacket(senddata,senddata.length, ipaddress, port);
serversoket.send(sendpacket);
}
}
}
- 10-08-2010, 09:18 AM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
And what does that code print?
(And please use code tags)
- 10-08-2010, 09:54 AM #12
Member
- Join Date
- Aug 2010
- Posts
- 11
- Rep Power
- 0
run:
hi
s=hi
- 10-08-2010, 10:02 AM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
This code:
produces this:Java Code:public static void main (String[] args) { String sentence= "blah"; for (int j = 0; j<5; j++){ System.out.print("s="+sentence+"<"); } }
s=blah<s=blah<s=blah<s=blah<s=blah<
So that output is not from that code.
Try it without reading the data, just assigning (as I do above) a fixed value to the sentence string.
- 10-08-2010, 12:52 PM #14
Member
- Join Date
- Aug 2010
- Posts
- 11
- Rep Power
- 0
Yes, you are right, thanks. I tried such as you did. It works, but where is my problem?!!!
- 10-08-2010, 01:00 PM #15
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Debug it.
It could be the "server" is hogging all the processing.
- 10-08-2010, 01:49 PM #16
Member
- Join Date
- Aug 2010
- Posts
- 11
- Rep Power
- 0
Would you please explain more detail, because I am almost new in java, thanks.
- 10-08-2010, 01:55 PM #17
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
I can't really explain debugging...use a debugger and step through the code.
- 10-08-2010, 01:58 PM #18
<Wrong post>
Last edited by Lund01; 10-08-2010 at 02:27 PM.
- 10-08-2010, 02:09 PM #19
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Well, no, what I meant was debugging as in using a debugger.
- 10-08-2010, 05:41 PM #20
Member
- Join Date
- Aug 2010
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
tracing java application line by line using netbeans
By chandrasekhar123 in forum NetBeansReplies: 1Last Post: 08-03-2010, 02:46 PM -
Formatting java command line output - Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07-02-2010, 02:20 PM -
Need to read an .ini and .abook file line by line (both files contain texts)
By ollyworks in forum Java AppletsReplies: 4Last Post: 09-10-2009, 10:18 AM -
Reading in a line of data and splitting the line up into variables
By guru32 in forum New To JavaReplies: 9Last Post: 04-07-2009, 03:51 AM -
Reading in data from file line by line
By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 12:19 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks