Dear friends
My program gets one word from server and it supposes to write this word in 2 lines.
Would you please guide me, which code arranges the output line? :confused:
Thx
Printable View
Dear friends
My program gets one word from server and it supposes to write this word in 2 lines.
Would you please guide me, which code arranges the output line? :confused:
Thx
Hi
Just write the word in two lines.
(Write the word in 2 lines in client which word comes from server)
Thx
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: ???
Hi
programmingprogrammingprogrammingprogrammingprogra mmingprogrammingprogrammingprogrammingprogrammingp rogrammingprogrammingprogrammingprogrammingprogram ming
programmingprogrammingprogrammingprogrammingprogra mmingprogrammingprogrammingprogrammingprogrammingp rogrammingprogrammingprogrammingprogrammingprogram ming
just in 2 line write programming (like chargen2)
thx
i think you have to copy your code at here
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
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
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.
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);
}
}
}
And what does that code print?
(And please use code tags)
run:
hi
s=hi
This code:
produces this: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.
Yes, you are right, thanks. I tried such as you did. It works, but where is my problem?!!!
Debug it.
It could be the "server" is hogging all the processing.
Would you please explain more detail, because I am almost new in java, thanks.
I can't really explain debugging...use a debugger and step through the code.
<Wrong post>
Well, no, what I meant was debugging as in using a debugger.
Hi
Would you please explain more about debugger?
Where is the location and how can I use it?
Thx