Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket/TCPIP help required

 
Tiger Scott
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • 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
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Peter,
Thanks.
You mean just open a Socket with:
Socket(String host, int port, InetAddress localAddr, int localPort)
Sanjay
 
Mirza Galib
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic