Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Client / Server communicate smoothly only when on same machine

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm creating a simple server client / server. The client has a list of names and sends them one at a time to the server, the server then tries to locate that name within an arrayList "WhatsWhat.srvrList". If the server finds the name it then returns some additional info from the arrayList to the client.

The communication works perfectly when both client and server are on the same machine, but I'm running into problems when the two are run on separate boxes. When they are run on separate machines, the client receives a seemingly random set of replies. If the client requests info on 10 names, I only end up with replies for 2 to 4. If on the other hand, I run client and server on the same box, I get all 10 replies.

Either the client or the server seems to be dropping information over the network, or somehow lagging behind. Is it unwise to be pulling data out of an arrayList as I've done? How can I ensure that the client waits to get a response for each name it sends?

Server:

Client:

 
Marshal
Posts: 28271
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jay Crawf wrote:Either the client or the server seems to be dropping information over the network, or somehow lagging behind.



What that suggests to me is that when you run the two things on the same machine, they are somehow sharing data in some way other than over the network. I say that because even when you run the client and the server on the same machine, the connection is still made through the operating system's networking code.

When you run the client and server on the same machine, are you running them in separate processes?
 
Jay Crawf
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:
When you run the client and server on the same machine, are you running them in separate processes?



I would think so, I don't even know how I could get them to run in the same process.
What I can tell you is that I built both the client and server, and moved the jar files from the development machine to another computer. Running out of separate folders on this new machine, the client and server are able to communicate without issue. But, if I move the client to yet a third machine, the communication is hit and miss... mostly miss, but some of the information does come across.
 
Jay Crawf
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my suspicion, the server is replying to the client with data it is pulling from an ArrayList "WhatsWhatUI.srvrList" - this arraylist is not static and is being actively and continuously updated in another thread... I'm getting the feeling this isn't too safe of a thing to do. When run on the same machine everything happens fast enough so it doesn't matter, but when done over an actual network connection it's slower, and the results get wonky.
 
Paul Clapham
Marshal
Posts: 28271
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jay Crawf wrote:This is my suspicion, the server is replying to the client with data it is pulling from an ArrayList "WhatsWhatUI.srvrList" - this arraylist is not static and is being actively and continuously updated in another thread... I'm getting the feeling this isn't too safe of a thing to do.



Really? I don't see any threads at all in the code you posted.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seeing the code, and noticing that it causes problems only if run on disparate hosts, I advise to read to read Don't println to a Socket.
 
Jay Crawf
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Seeing the code, and noticing that it causes problems only if run on disparate hosts, I advise to read to read Don't println to a Socket.



Hrm, none of the hosts used was a Mac, but worth a shot though. The server's in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); seems totally unable to receive from the clients out.print(anything at all); though.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem described in the article is not Mac-specific (or OS X-specific); it would happen on any Unix/Linux-based OS.
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic