• 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

Socket/TCPIP help required

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have to open a socket connection to a server using the providers documentation. Can somebody help translate it in Java for me. This is what the documentaion has:
fd=socket(AF_INET,SOCK_STREAM,TCP_PROTO)
myaddr=(socket structure){AF_INET,wsport,myIPAddr)
bind(fd,myaddr)
apiaddr=(socketaddr structure){AF_INET,SERVER_PORT,serverIPaddr)
connect(fd,apiaddr)
AF_INET=2, SOCK_STREAM=2,TCP_PROTO=6
wsport= a unique client port
myIPAddr= client IPAddr
SERVER_PORT,serverIPaddr- known
fd- definition of socket connection
Thanks a lot,
Sanjay
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To me it looks like this is just opening a TCP socket connection to the server -- i.e. you can simply instantiate a java.net.Socket, get the input- and/or output stream and off you go.
- Peter
 
Tiger Scott
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter,
Thanks.
You mean just open a Socket with:
Socket(String host, int port, InetAddress localAddr, int localPort)
Sanjay
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
open a socket with:
Socket soc = new Socket("200.200.200.200",3333) ;
///////////
get the stream

Input Stream = soc.getInputStream());
////////
There is also a catch in it
they are also asking to bind it
They could also be talking about a ServerSocket
Syntax for it is
ServerSocket ser = new ServerSocket(3333);
Socket soc = ser.accept();

Accept method will return the value of incoming socket in the form of socket.
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic