socket programing low-level | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

8th Sep 2021, 2:24 PM
Mehran
Mehran - avatar
4 Answers
+ 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
9th Sep 2021, 7:38 AM
Doooms
Doooms - avatar
+ 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
9th Sep 2021, 8:06 AM
Mehran
Mehran - avatar
+ 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
9th Sep 2021, 7:45 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
0
you are try connect client to client, but .connect() expects server. Use ServerSocket ss = new ServerSocket();
9th Sep 2021, 8:58 AM
zemiak