-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network Programming with Java Sockets #9
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Network Programming in Java is an interesting topic. But the question is, is this really for a beginner?
i felt it's an important topic for a complete course as also u've covered concepts related to concurrency (also I'm doing hacktober fest) |
public class Server { | ||
public static void main(String[] args) { | ||
try(ServerSocket serverSocket = new ServerSocket(5000)){ | ||
System.out.println("listening to port:5000"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preffer use logger
BufferedReader iStream = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); | ||
PrintWriter oStream = new PrintWriter(clientSocket.getOutputStream(),true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close stream
good practice is close stream by try()
sendFile("path/to/File1.pdf"); | ||
sendFile("path/to/File2.pdf"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PLease set this params to config
dataInputStream = new DataInputStream(socket.getInputStream()); | ||
dataOutputStream = new DataOutputStream(socket.getOutputStream()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to close streeams you should use try()
DatagramPacket packet = new DatagramPacket(inData,inData.length); | ||
socket.receive(packet); | ||
|
||
InetAddress address = packet.getAddress(); | ||
int port = packet.getPort(); | ||
|
||
String message = new String(inData,0,packet.getLength()); | ||
System.out.println("client@"+port+": "+message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
divide into smaller method
No description provided.