I am using the RUDP protocol to send and receive packets using this very useful java library wich implements the RUDP protocol in java. The design of the library is very similar to TCP. It comparatively uses a ReliableServerSocket
as a ServerSocket and a ReliableSocket
as a Socket.
I do however stumble upon an error when i create a client connection to the server. The connection between the server and client is successfully created because everything past accept() method is executed. However the inputstream doesn't hold any bytes when trying to read from it.
Client:
public class Client {
ReliableSocket rs;
public Client() throws IOException {
rs = new ReliableSocket();
rs.connect(new InetSocketAddress("127.0.0.1", 3033));
String message = "Hello";
byte[] sendData = message.getBytes();
OutputStream os = rs.getOutputStream();
os.write(sendData, 0, sendData.length);
}
public static void main(String[] args) throws IOException {
new Client();
}
}
Server:
public class Server {
ReliableServerSocket rss;
ReliableSocket rs;
public Server() throws Exception {
rss = new ReliableServerSocket(3033);
while (true) {
rs = (ReliableSocket) rss.accept();
System.out.println("Client connected");
byte[] buffer = new byte[100];
InputStream in = rs.getInputStream();
in.read(buffer);
//here the value doesn't return from the inputstream
System.out.println("message from client: " + new String(buffer).trim());
}
}
public static void main(String[] args) throws Exception {
new Server();
}
}