user3011052:
I need to create a P2P application in java that can send messages to other applications that use the same protocol.
In order to connect with another application, I must pass in their IP and Port through the command line and connect to it.
Related Articles
This is the problem, I am unable to find out how to connect (establish the connection) given the IP and port number.
My professor has set up a test peer on:
honeybee.cs.usm.maine.edu
port 12030
The IP is for honeybee.cs.usm.maine.edu is 130.111.131.121
So my question is how do I establish a connection to this port on this server?
I just want to be able to send and recieve strings from the test peer.
Right now the only way I can do this is through telnet with
telnet 130.111.131.121 12030
So far I have:
public static void main(String[] args) throws UnknownHostException, IOException {
int portNumber = 12038;
String recieverIP = "130.111.131.121";
int recieverPort = 12030;
ServerSocket serverSocket = new ServerSocket(portNumber);
System.out.println("Creating server socket on Port " + portNumber);
Socket clientSocket = new Socket(recieverIP, recieverPort);
System.out.println("Establishing connection to " + recieverIP + " on port " + recieverPort);
OutputStream os = clientSocket.getOutputStream();
PrintWriter pw = new PrintWriter(os, true);
try {
BufferedReader input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); //input stream
PrintStream output = new PrintStream(new BufferedOutputStream(clientSocket.getOutputStream())); //output stream
String Test = "Sending This String";
pw.println(Test); // sends the string to server
String readIn = input.readLine(); // should give back an error message but it doesn't!
System.out.println("message recieved " + readIn);
} catch (IOException e) { e.printStackTrace(); }
}
I basically want to be able to send and recieve a string between this server.
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE