Your Ad Here

Friday, February 6, 2009

Read from Input.txt (socket programming)

My question is how do I read from the user Datainput.txt file to get the value of myVal?

I can handle all the other stuff required for this, but with out the correct value to start well nothing will be right.


Code:
---------
public class MyClient {
private final int myServerPort = 0x28b5;
private final String myServerAddr = "127.0.0.1";

public static void main (String[] args) {
try {
new MyClient ().go ();
} catch (Exception e) {
System.err.println (e);
}
}

private void go ()
throws IOException, SocketException, UnknownHostException {
DatagramSocket dgSocket = new DatagramSocket ();
InetAddress inAddr = InetAddress.getByName (myServerAddr);
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
String message;

int seqi=0; //seqnumber
int myVal = ; // read number from file DataInput.txt

do { // read a number from user and send it to the server
byte byToIn[] = new byte[8];
// convert myVal into 4 bytes
// convert seqi into 4 bytes

seqi++;


DatagramPacket dgPacket = new DatagramPacket (byToIn, byToIn.length, inAddr, myServerPort);
dgSocket.send (dgPacket);
} while (seqi<32);

dgSocket.close ();
}
}
---------
I also have the Server side, but did not think this was relevant. If needed I will post that also.

Read More...

[Source: Code Forums - Posted by Kishore Vengala]
Your Ad Here

No comments: