• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

ServerSocketChannel.accept() seems to create a random port to send data to?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey!

I'm new to Java and server/client programming and I'm writing a non-blocking nio socket server that connects to flash clients for a chat application. The flash client can connect and send data fine to the server, but receiving data is a different story.

I checked everything -- the data I want to send is getting all the way to the SocketChannel.send(ByteBuffer) and it's writing all of the data. I printed out the socket's port (I'm assuming that that's the port that the socket is writing to, as opposed to the local port which it listens on) and it was some random port (not the port that Flash is listening on). I'm guessing that's the problem. Shouldn't there be just one port if it's a socket? How do I keep the same read / write port?

Thanks!
Tucker

(First post!)

Edit: I checked ethereal and it looks like the flash client is specifying the port it's listening on and sending that to the server. I'm still boggled as to why it's not receiving the data, though
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch.

Tucker Connelly wrote:I printed out the socket's port (I'm assuming that that's the port that the socket is writing to, as opposed to the local port which it listens on) and it was some random port (not the port that Flash is listening on). [/i]



I'm confused. Who's the client in this case? Flash?
The way TCP works, regardless of language, is a server listens to a port, let's say X. A client attempts to connect to port X. If the connection is successful, the connection on the server side will be switched to a random port so the server can continue to listen for more connections to X. This process is transparent to the client and server. You should not be worrying about port numbers, except for that initial connection. Show us some code and we'll see if we can sort it out.
 
Tucker Connelly
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply! I built a quick Java socket client and it connected and received the data just fine from the server. Then I tried using the Flash client with a PHP socket server I made and it worked fine too. This leads me to believe it's a problem with the NIO classes connecting to flash : /

Anyways, here is the code for the NIO server (built using this tutorial):



Thanks a ton to anyone who helps!
 
Tucker Connelly
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved! Flash won't trigger the event that says there's data available unless the data is terminated by a null byte!
 
I do some of my very best work in water. Like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic