Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine if socket is connected

Status
Not open for further replies.

SMURF75

Programmer
Aug 28, 2004
87
GB
Hi!

I have a sequence where i create,open and send data to a socket. My problem is that if the IP thats used as end point not exists the socket still thinks its doing everything okay. And after the end of the transmit I stand there without any receipt(the data goes to a network printer who prints a receipt) and no errormessage, and abolutely no clue about how to catch it.

Code:
' Set up the socket and connect
socPrinter = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP)
Dim addr As IPAddress = IPAddress.Parse(strPrinterIP)
Dim ipep As IPEndPoint = New IPEndPoint(addr,intPrinterPort)
socPrinter.Connect(ipep)
              
' Output bytes to printer and close socket.
socPrinter.Send(bytBuffer, 0, bytBuffer.Length, SocketFlags.None)
socPrinter.Close()
socPrinter = Nothing

Ive tried to use socket.connected but that just returns sockets last state, which somehowe is true even though it doesnt exist a computer on the end point.
Ive also tried to handle it with the integer that socket.send returns. But i get the same value, success or fail doesnt matter.

Guess im missing something vital here so please point it out to me ;)

- - - - - - - - - - - - - - - - - -
Im three apples high, Im blue, and i most certainly like that cold beer that should be every mans right after a hard days work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top