Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
Server
domenica 18 aprile 2004 - 13.22
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
19018
Profilo
| Expert
502
messaggi | Data Invio:
dom 18 apr 2004 - 13:22
ecco il codice di una semplice sub che crea un socket e lo pone in ascolto :
Private Sub ServerSock()
Dim ipendp As IPEndPoint
Dim s As Socket
Dim tempRemoteEP As EndPoint
Dim buffer(1024) As Byte
Try
ipendp = New IPEndPoint(IPAddress.Any, 0)
s = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
tempRemoteEP = CType(ipendp, EndPoint)
s.ReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, tempRemoteEP)
TextBox1.Text = Encoding.ASCII.GetString(buffer)
Catch e As Exception
MessageBox.Show("Errore : " & e.ToString, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
Finally
s.Shutdown(SocketShutdown.Receive)
s.Close()
End Try
End Sub
PERCHE' mi da errore alla riga : s.ReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, tempRemoteEP) ??????
grazie
Brainkiller
Profilo
| Guru
7.999
messaggi | Data Invio:
lun 19 apr 2004 - 00:58
Ti posto del codice C# che è sicuramente funzionante. Prendi spunto e cerca di correggere il tuo:
string ip="100.100.100.100";
Socket s=new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
s.Connect(new IPEndPoint(IPAddress.Parse(ip),port));
Byte[] sendd=new byte[15];
sendd[0] = (byte)0xff;
sendd[1] = (byte)0xff;
sendd[2] = (byte)0xff;
sendd[3] = (byte)0xff;
sendd[4] = Convert.ToByte('g');
sendd[5] = Convert.ToByte('e');
sendd[6] = Convert.ToByte('t');
sendd[7] = Convert.ToByte('s');
sendd[8] = Convert.ToByte('t');
sendd[9] = Convert.ToByte('a');
sendd[10] = Convert.ToByte('t');
sendd[11] = Convert.ToByte('u');
sendd[12] = Convert.ToByte('s');
sendd[13] = Convert.ToByte('\n');
sendd[14] = Convert.ToByte('\0');
s.Send(sendd);
byte[] rec=new byte[1024];
s.Receive(rec);
s.Close();
string beta=Encoding.ASCII.GetString(rec);
ciao
david
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !