23-03-13, 12:02 PM
السلام عليكم
جرب هذا الكود للReceive
المثال يعمل معي بالسي شارب ولم استطع تحميل المثال الذي ارفقته لكن ساحاول ان احمله واجرب
جرب هذا الكود للReceive
PHP كود :
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO
Imports System.Net.Sockets
Imports System.Net
Imports System.Threading
Imports System.Reflection
Imports StudentInfo
Namespace ReceiveAnObject
Public Partial Class Form1
Inherits Form
Private th As Thread
Private listen As TcpListener
Private ns As NetworkStream
Private bf As BinaryFormatter
Private sok As Socket
Private stdinfo As SerializeStdInfo
Public Sub New()
InitializeComponent()
th = New Thread(New ThreadStart(AddressOf Receive_Info))
th.Start()
End Sub
Private Sub get_info()
Me.Invoke(New MethodInvoker(Sub()
idtxt.Text = stdinfo.id.ToString()
nametxt.Text = stdinfo.name
agetxt.Text = stdinfo.age.ToString()
depttxt.Text = stdinfo.dept
avgtxt.Text = stdinfo.avg.ToString()
label6.Text = "Data have been received!"
End Sub))
End Sub
Private Sub Receive_Info()
'Creating a new instance of class TcpListener
listen = New TcpListener(IPAddress.Any, 9000)
'Start Listening
listen.Start()
'Infinite loop
While True
'Accept the connecting
sok = listen.AcceptSocket()
'Creating a new instance of class NetworkStream
ns = New NetworkStream(sok)
'Creating a new instance of class BinaryFormatter
bf = New BinaryFormatter()
'Deserializing the Stream into the Object (Class)
stdinfo = DirectCast(bf.Deserialize(ns), SerializeStdInfo)
'Getting the deserialized data
get_info()
'Release the stream
ns.Flush()
'Close the stream
ns.Close()
End While
End Sub
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs)
th.Abort()
listen.[Stop]()
End Sub
End Class
End Namespace
المثال يعمل معي بالسي شارب ولم استطع تحميل المثال الذي ارفقته لكن ساحاول ان احمله واجرب
