Socket class

raman_xs

New member
Joined
Feb 6, 2006
Messages
2
Programming Experience
1-3
i want to know how to send data from one pc to another in a network using the Socket class in VB.NET.

please send some code along with your suggetions

Thanks
 
Socket Error: The requested address is not valid in its context

hi,

i'm writing the following code for the server:

Shared Sub Main()
' Must listen on correct port- must be same as port client wants to connect on.
Const portNumber As Integer = 139
Dim tcpListener As New TcpListener(System.Net.IPAddress.Parse("192.168.0.23"), 445)
tcpListener.Start()
Console.WriteLine("Waiting for connection...")
Try
'Accept the pending client connection and return a TcpClient initialized for communication.
Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
Console.WriteLine("Connection accepted.")
' Get the stream
Dim networkStream As NetworkStream = tcpClient.GetStream()
' Read the stream into a byte array
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Return the data received from the client to the console.
Dim clientdata As String = Encoding.ASCII.GetString(bytes)
Console.WriteLine(("Client sent: " + clientdata))
Dim responseString As String = "Connected to server."
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(responseString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Console.WriteLine(("Message Sent /> : " + responseString))
'Any communication with the remote client using the TcpClient can go here.
'Close TcpListener and TcpClient.
tcpClient.Close()
tcpListener.Stop()
Console.WriteLine("exit")
Console.ReadLine()
Catch e As Exception
Console.WriteLine(e.ToString())
Console.ReadLine()
End Try
End Sub

When I run this code, i get the error message: The requested address is not valid in its context.

Could anyone suggest a workaround for this problem

 
Back
Top