Programacion
clientSocket.Connect ("127.0.0.1", 8888) When client gets connected, it reads data from NetworkStream, and also writes to NetworkStream. When you start the client program you will get message client started. When we press the button at the bottom it sends a message to Server and also receives a message from Server.
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Dim clientSocket As NewSystem.Net.Sockets.TcpClient()
Dim serverStream As NetworkStream
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim serverStream As NetworkStream = clientSocket.GetStream()
Dim outStream As Byte() = _
System.Text.Encoding.ASCII.GetBytes("Message from Client$")
serverStream.Write(outStream, 0, outStream.Length)
serverStream.Flush()
DiminStream(10024) As Byte
serverStream.Read(inStream, 0, CInt(clientSocket.ReceiveBufferSize))
Dim returndata As String = _
System.Text.Encoding.ASCII.GetString(inStream)
msg("Data from Server : " + returndata)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
msg("Client Started")
clientSocket.Connect("127.0.0.1", 8888)Label1.Text = "Client Socket Program - Server Connected ..."
End Sub
Sub msg(ByVal mesg As String)
TextBox1.Text = TextBox1.Text + Environment.NewLine + " >> " + mesg
End Sub
End Class
vb.net_client_socket_program.JPG
Before you run the Client Socket Program you should start Server Socket Program first. For more details of running this program, take a look at the VB.NET SocketProgramming article I have posted before.
If this tutorial doesn't answer your question, and you have a specific question, just ask an expert here. Post your question to get a direct answer
Socket.SendFile (Método) (String, Byte[], Byte[], TransmitFileOptions)
.NET Framework 2.0
Otras versiones
http://i3.msdn.microsoft.com/Hash/c764fa3d6b8a84bd40aa131355215c98.png
Personas que lo hanencontrado útil: 0 de 1 Valorar este tema
Nota: este método es nuevo en la versión 2.0 de .NET Framework.
Envía el archivo fileName y búferes de datos a un objeto Socket conectado mediante el valor TransmitFileOptions especificado.
Espacio de nombres: System.Net.SocketsEnsamblado: System (en system.dll)
http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gifSintaxis
C#
C++VB
public void SendFile (
string fileName,
byte[] preBuffer,
byte[] postBuffer,
TransmitFileOptions flags
)
J#
public void SendFile (
String fileName,
byte[] preBuffer,
byte[] postBuffer,
TransmitFileOptions flags
)
JScript
public function SendFile (
fileName : String,
preBuffer : byte[],
postBuffer : byte[],
flags : TransmitFileOptions
)
Parámetros
fileName
Stringcon la ruta de acceso y el nombre del archivo que se ha de enviar. Este parámetro puede ser referencia de objeto null (Nothing en Visual Basic).
preBuffer
Matriz Byte con datos para enviar antes de enviar el archivo. Este parámetro puede ser referencia de objeto null (Nothing en Visual Basic).
postBuffer
Matriz Byte con datos para enviar después de enviar el archivo. Este parámetro puedeser referencia de objeto null (Nothing en Visual Basic).
flags
Uno o varios de los valores de TransmitFileOptions.
http://i.msdn.microsoft.com/Hash/030c41d9079671d09a62d8e2c1db6973.gifExcepciones
Tipo de excepción | Condición |
NotSupportedException | El sistema operativo no es Windows NT o una versión posterior. O bien El socket no está conectado a un host remoto. |...
Regístrate para leer el documento completo.