socket programing low-level | Sololearn: Learn to code for FREE!

+3

socket programing low-level

i am trying to understand low-level of socket programing.(i am already familiar with high-level) what's wrong in my code? https://code.sololearn.com/ciXMSyVM55qa/?ref=app

9/8/2021 2:24:29 PM

Mehran

4 Answers

New Answer

+1

hey, I'm still learning about sockets so I found this problem interesting. why is it that you bind s->sa and then try to connect s->ssa? by the error we can see that the connection is being refused. I guess the binding to diff address is not allowing this I tinkered with your code and saw that if I bind and connect to the same address respectively it works... but I don't get what you are trying to achieve https://code.sololearn.com/cFDvaDIA1AoR/?ref=app

+1

Doooms as you can see in this example Each socket has a local port and a port. In normal connections, the value of the server side socket port is the same as the client socket localport and the value of the client socket port is the same as the server side socket localport. and the output stream of client socket is the input stream of server side socket and vice versa. bind method determines the local port of socket and connect method determines the port. i think local port is source address and port is destination I may be wrong, so I ask. https://code.sololearn.com/cE1V9gm6Qusj/?ref=app

+1

You haven't start listening And why you are trying to make server and client in same program? This is not going to work. Or else you have to use multi threading

0

you are try connect client to client, but .connect() expects server. Use ServerSocket ss = new ServerSocket();