Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
DavidNorep - 06 Jun 2007 19:03 GMT
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].
Gordon Beaton - 06 Jun 2007 19:25 GMT
> 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

--
Mark Space - 06 Jun 2007 23:29 GMT
> 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.
DavidNorep - 07 Jun 2007 12:22 GMT
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.
Gordon Beaton - 07 Jun 2007 13:06 GMT
> 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

--
DavidNorep - 07 Jun 2007 14:34 GMT
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)?
Gordon Beaton - 07 Jun 2007 15:08 GMT
> 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

--


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.