Created
March 25, 2018 18:40
-
-
Save aurorapar/20cc1cc01f48ddfb6cc0f7068c68c8f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Client | |
import java.net.*; | |
import java.io.*; | |
public class Client | |
{ | |
public static void main(String args[]) | |
{ | |
byte buffer[] = new byte[100]; | |
int serverPort = 69; | |
try | |
{ | |
InetAddress serverAddress = InetAddress.getLocalHost(); | |
Socket socket = new Socket(serverAddress,serverPort); | |
InputStream in = socket.getInputStream(); | |
int nbr = in.read(buffer,0,buffer.length); | |
if(nbr > 0) | |
System.out.println(new String(buffer,0,nbr)); | |
else | |
System.out.println("No message received"); | |
socket.close(); | |
} | |
catch(Exception e) | |
{ | |
System.out.println(e.toString()); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Server | |
import java.net.*; | |
import java.io.*; | |
import java.util.*; | |
public class Server | |
{ | |
public static void main(String args[]) | |
{ | |
int serverPort = 69; | |
try | |
{ | |
ServerSocket server = new ServerSocket(serverPort); | |
while(true) | |
{ | |
Socket serverSocket = server.accept(); | |
OutputStream replySocket = serverSocket.getOutputStream(); | |
Date date = new Date(); | |
String s = date.toString(); | |
replySocket.write(s.getBytes(), 0, s.length()); | |
serverSocket.close(); | |
} | |
} | |
catch(Exception e) | |
{ | |
System.out.println(e.toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment