Hello everyone,
I am facing a problem how to call api (web service) over tcp. Does anyone has a sample code?
Really appreciate your help.
What I think Milica Maksimović is saying, all connections are either TCP or UDP (a few ICMP, but I will leave that out here). HTTP is 99% of the time TCP. UDP is almost only used for video streaming. The main difference is that TCP guarentees a quality check of the packages and will resend those that are broken, UDP just delivers without checking. The reason for using UDP for video is that it would be too "expensive" to resend packages when streaming video and would most likely cause delays too. This is the reason you see pixelations.
To communicate through TCP you must have a protocol and this is where HTTP comes in. So the question is, what is the protocol?
Given you want to connect to a “web service”, i assume that service is speaking HTTP. There are several Java libraries that speak HTTP, and if the API is actually a REST API as Milica Maksimović suspects, you are in an even better position, as there are a lot of REST libraries, too.
Also, if it’s a well-known service like Twitter or SendGrid, it may have an actual Java SDK to communicate with their API without actually doing any networking stuff.
a raw tcp / udp call usually uses sockets.
baeldung.com/a-guide-to-java-sockets
you mean something like this?
What type of API are you trying to call? If you use REST API, and use HTTP to call it, you're basically using TCP. HTTP utilizes TCP to transfer information.
quincybatten
developer
try this simple... Java TCP Client Server example