Skip to content

Conversation

@HeptaDecane
Copy link

No description provided.

Copy link

@jfullstackdev jfullstackdev left a 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?

@HeptaDecane
Copy link
Author

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");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preffer use logger

Comment on lines +11 to +12
BufferedReader iStream = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
PrintWriter oStream = new PrintWriter(clientSocket.getOutputStream(),true);
Copy link

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()

Comment on lines +13 to +14
sendFile("path/to/File1.pdf");
sendFile("path/to/File2.pdf");
Copy link

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

Comment on lines +10 to +11
dataInputStream = new DataInputStream(socket.getInputStream());
dataOutputStream = new DataOutputStream(socket.getOutputStream());
Copy link

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()

Comment on lines +13 to +20
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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divide into smaller method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants