-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocketProgramming2.java
More file actions
31 lines (25 loc) · 1.1 KB
/
SocketProgramming2.java
File metadata and controls
31 lines (25 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.net.*;
import java.io.*;
import java.lang.*;
class SocketProgramming2{
public static void main(String[] args) throws Exception{
if(args.length<2 || args.length>3){
throw new RuntimeException("Dammit, thats not the correct number of arguments");
}
Socket socket=new Socket(args[0], (args.length==3)?Integer.parseInt(args[2]):7);
// InputStream in=socket.getInputStream();
// OutputStream out=socket.getOutputStream();
// String toWrite="Hello, World";
// out.write(toWrite.getBytes());
// int totalBytesRcvd=0;
// int bytesRcvd=0;
// while(toWrite.getBytes().length > totalBytesRcvd){
// if ((bytesRcvd = in.read(toWrite.getBytes(), totalBytesRcvd,
// toWrite.getBytes().length - totalBytesRcvd)) == -1)
// throw new SocketException("Connection closed prematurely");
// totalBytesRcvd += bytesRcvd;
// }
// System.out.println("Received: " + new String(toWrite.getBytes())) ;
// socket.close();
}
}