How to debug client/server that communicate via sockets on a PC?

D

DavidNorep

Can you please suggest me how can I debug a clinet/server sw that
communicate via sockets on my home PC, for the first stage of testing.
I have another PC at home and a router, and Internet security, and
Windows. My router panel shows me my external IP, and ipconfig on the
computers are 10.0.0.[12].
 
G

Gordon Beaton

Can you please suggest me how can I debug a clinet/server sw that
communicate via sockets on my home PC, for the first stage of
testing. I have another PC at home and a router, and Internet
security, and Windows. My router panel shows me my external IP, and
ipconfig on the computers are 10.0.0.[12].

Debug what problem, specifically?

Regardless, try Wireshark (formerly Ethereal).

/gordon

--
 
M

Mark Space

DavidNorep said:
Can you please suggest me how can I debug a clinet/server sw that
communicate via sockets on my home PC, for the first stage of testing.

Break it into smaller pieces and test each piece separately. That's the
first stage of testing, always. You may have to refactor your code to
allow for efficient testing.

Once you get everything working separately, put it together (maybe not
all at once, i.e., test progressively larger chunks) and test the client
and the server on the same machine. Don't use address 10.0.0.12, use
127.0.0.1, the loopback address.
 
D

DavidNorep

How do I simulate the ports that the socket uses? Suppose that I want
that the server that runs on my PC will read from port X.

Can the client that runs on my PC write to this port and the server
will succeed to read it?

I assume that if the above is true I can also run several clients on
my PC, and they will write to that socket.

I also have a really beginner question. When the client writes to the
server socket in another computer - does he need to specify the socket
in his computer through which the data goes out? There is a client
Socket constructor with 4 parmeters srv-ip, srv-socket, clt-ip, clt-
socket, but the examples I saw - in Sun tutorial for example - use the
two parameters Socket constructor.
 
G

Gordon Beaton

How do I simulate the ports that the socket uses? Suppose that I want
that the server that runs on my PC will read from port X.

Can the client that runs on my PC write to this port and the server
will succeed to read it?

Yes. Connect to that port and write to the resulting
(Socket)OutputStream.
I assume that if the above is true I can also run several clients on
my PC, and they will write to that socket.

Yes, but each client will have its own socket. At the server, there
will be one socket per client. All of the sockets will share the same
port number at the server end of the connection.
I also have a really beginner question. When the client writes to the
server socket in another computer - does he need to specify the socket
in his computer through which the data goes out? There is a client
Socket constructor with 4 parmeters srv-ip, srv-socket, clt-ip, clt-
socket, but the examples I saw - in Sun tutorial for example - use the
two parameters Socket constructor.

Don't confuse sockets and ports. A socket is one half of a connection
(i.e. a connection endpoint), while a port is more like an address
used to discern between different services.

The normal situation is that the server specifies only the port number
to listen on, and the client specifies the address and port number of
the server.

The client's outgoing port is irrelevant in virtually all cases, and
when the client doesn't specify one the system will choose an
available "ephemeral" port for it.

All of your clients can connect to the same server port, regardless of
whether they come from the same client host or not (unless you have
more than 64k of them, in which case they will need to come from
multiple hosts).

/gordon

--
 
D

DavidNorep

Many thanks.

Now one more question: I have two clients who communicate via sockets.
Should each one of them create a Socket (and ServerSocket is not
necessary at all)?
 
G

Gordon Beaton

Now one more question: I have two clients who communicate via
sockets. Should each one of them create a Socket (and ServerSocket
is not necessary at all)?

The ServerSocket is necessary in order to establish the connection,
without it there's nothing to connect *to*.

One of the "clients" will have to be a server if they are to
communicate with each other.

/gordon

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top