I am getting an error whenever I try to send data to a server in c# using System.Net.Sockets and Xamarin. I am only getting this error when sending data but not connecting. The error message is "Exception thrown: 'System.Net.Internals.SocketExceptionFactory.ExtendedSocketException' in System.Net.Sockets.dll" I am not sure how to fix this but here is my connection code running when a button is pressed.
Label label = this.FindByName<Label>("label");
Socket sock;
string ipI = "127.0.0.1";
int portI = 6419;
IPAddress ipAddress = IPAddress.Parse(ipI);
IPEndPoint remoteEndPoint = new IPEndPoint(ipAddress, portI);
sock = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(remoteEndPoint);
byte[] sData = Encoding.ASCII.GetBytes(num);
sock.Send(sData);
label.Text = "Added 1 to server";
sock.Dispose();
instead of websocket try using tcpclient:
try
{
TcpClient client = new TcpClient(127.0.0.1, 6419);
NetworkStream ns = client.GetStream();
byte[] bytes = new byte[1024];
int bytesRead = await ns.ReadAsync(bytes, 0, bytes.Length);
string result = Encoding.ASCII.GetString(bytes, 0, bytesRead);
client.Close();
return result;
}
catch (Exception e)
{
return null;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.