Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket and TCP in java [duplicate]

Tags:

java

tcp

sockets

Possible Duplicate:
how to implement TCP server and TCP client in java to transfer files

I write application which will send files to server through socket. Its very important to all files came correct from client to server with no errors, lost data and other like that. To do that I need to use TCP protocol I think but I dont know how to do that. Is socket in Java is default using TCP. If not how can I send data through TCP? Thanks for any help and tip.

like image 264
klemens Avatar asked Oct 14 '11 13:10

klemens


People also ask

Do java sockets use TCP?

There are two communication protocols that we can use for socket programming: User Datagram Protocol (UDP) and Transfer Control Protocol (TCP).

What is difference between socket () and ServerSocket () class?

Here, two classes are being used: Socket and ServerSocket. The Socket class is used to communicate client and server. Through this class, we can read and write message. The ServerSocket class is used at server-side.

What are TCP IP sockets in java?

Definition: A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to. An endpoint is a combination of an IP address and a port number.

Does java use TCP or UDP?

Java provides the reliable stream-based communication for TCP as well as the unreliable datagram communication for UDP.


1 Answers

Yes, you can use TCP for this and yes, Java sockets can do TCP.

If I were you, I'd start by following this tutorial: http://download.oracle.com/javase/tutorial/networking/sockets/

like image 153
NPE Avatar answered Nov 14 '22 23:11

NPE