Skip to content

Tag: sockets

Java socket only use loopback

I have tried to connect my laptop to another laptop (on the same network, both using Windows 10) using java socket. Here is the client code : And the server code : But for some reason, even if I specify an ip address, the laptop only look for a host in loopack, not on the private network. Here is the

Socket binding through JNI

I try to open a socket connection on a Linux machine through JNI. If I combine Java_Socket_socket and Java_Socket_bind in same C function, the JNI call works perfectly, but it doesn’t work when I run methods sequentially. This is my code Java code Output: If I create C program from this code, and as reg…

Why are multiple sockets created by one client

Multiple sockets created by one client The task is to create a server-client communication with sockets. The client is the browser and it requests an html file. The server listens and accepts the connection if a request is made. I would like to create one thread/client (persisten connection), but can’t …

Server doesn’t forward message to all in the chat

i am trying to create a simple chat app using java sockets, the server is threaded, when a client connects its socket is added to an ArrayList, so that i can send to all in that list. the problem is when 3 clients are connected, the for loop that sends doesn’t work properly, for ex : client 0 sends to

Java ProxySelector undefined behaviour

I am experimenting with Proxies in java networking. I have read the documentation regarding them and am currently testing ProxySelector. I notice 2 types of behaviour of this ProxySelector when using with HttpURLConnection & when using with Socket class When using with HttpUrlConnection with this code I g…

Read a socket direclty from InputStream or from BufferedReader?

My goal is to read the n number of bytes from a Socket. Is it better to directly read from the InputStream, or wrap it into a BufferedReader? Throughout the net you find both approaches, but none states which to use when. Answer Since your goal is to “read the n number of bytes” there is little po…