Mostafa Ghadimi
Mostafa Ghadimi

Reputation: 6756

Implement Socket class in java for special purpose

I'm pretty new to Java programming and I don't have permission to use java built-in libraries, specifically Socket and ServerSocket. I should implement a server-client program that whenever client connects to the server, server gets its name and give them some tasks.

My question is how to implement the Socket and ServerSocket for this purpose. I have searched over internet and the results was disappointing for me. I would be Thankful if anyone could help me.

Upvotes: 0

Views: 82

Answers (1)

Loïc Le Doyen
Loïc Le Doyen

Reputation: 1055

If your goal is to establish a TCP connection without Java's Socket (or AsynchronousSocketChannel) or accept TCP connections without Java's ServerSocket (or AsynchronousServerSocketChannel) I would say that you cannot do it, in Java.

If you read the code of these classes, you will find many native method calls, meaning native OS-specific code is being used.

So you could write some C code to implement your own version of a TCP connection and use it in your Java code using JNI.

Is that what this assignment is supposed to make you learn ?

Upvotes: 1

Related Questions