Results 1 to 8 of 8

Thread: Socket Class.

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Socket Class.

    How do sockets work in java? I have only previously been exposed to the VB winsock control, which receives data automatically as an event. From a tutorial i've seen, it looks like all incoming data has to be manually read using a bufferedreader, perhaps using a continuous loop, is that how it goes?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Socket Class.

    That's one way. The other way is using the New I/O channels to poll which sockets have data available.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Socket Class.

    The URL class can be used also. All you do is invoke openStream() on an instance of a URL to get an InputStream which can then be used to read the contents of the URL. You can also invoke openConnection() on A URL instance to get an URLConnection so you can read/write.

    For lower level communication i would use Sockets though. Say if you were writing a client-sever appliction and you wanted to implement some sort of custom protocol.

  4. #4

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: Socket Class.

    Yes, I'm writing a client-server application. The server is actually in VB, I just need to get a working client apllication going. I'm only sending and receiving simple text strings, so which method would work best, and can you give me a code example?
    Last edited by Nove; Jun 19th, 2005 at 04:56 PM.

  5. #5
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Socket Class.

    I can't give you a code example, but I would go with polling the sockets as CB suggested. I tried making a simple chat program and looping continously readinng from the socket even if it was null was very slow and usually locked up the application.

  6. #6
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Socket Class.

    Nove why not just write the client in VB? You already have the server side code written. I wouldn't add to the complexity by writing a cross language program until i knew exactly both sides.

  7. #7

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: Socket Class.

    Well, I have written the client in VB, but it'll be much easier on the user if they can just log on through a web browser. This also gives me a good chance to get some Java learning in.

  8. #8
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Socket Class.

    Here is a small applet that I wrote for one of my web pages for our Help Desk. It may be capable of doing a bit more than you intend, but it should get you started.

    It 'talks' to a C server, but I have done the same thing with VB. It isn't necessary, but I put the variables to be sent/redeived in classes that match the C struct or VB UDT. It's helpful when you dealing with very large complicated structures.

    You will have to convert any Longs and Integers in your VB app to/from network-byte-order (big-endian). The read/write methods in the Java classes automatically do the conversions.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width