Server

domenica 18 aprile 2004 - 13.22

19018 Profilo | Expert

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

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
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 !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5