Witam,
Nie mam pojecia dlaczego sie wywala. O Co chodzi. Robie tak samo jak gość w tutorialu a nadal wywala mi błąd na pozycji:
_socket.Bind(new IPEndPoint(IPAddress.Parse("127.0.01"), 1024));
błąd:
Additional information: Odwołanie do obiektu nie zostało ustawione na wystąpienie obiektu.
Prośba o wsparcie.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace Server
{
class ServerNo
{
private Socket _socket;
private byte[] _buffer = new byte[1024];
public void ServerSocket()
{
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
}
public void Bind()
{
_socket.Bind(new IPEndPoint(IPAddress.Parse("127.0.01"), 1024));
}
public void Listen(int backlog)
{
_socket.Listen(3);
}
public void Accept()
{
_socket.BeginAccept(AcceptedCallBack, null);
}
public void AcceptedCallBack(IAsyncResult result)
{
_buffer = new byte[1024];
Socket clientSocket = _socket.EndAccept(result);
clientSocket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, ReceiveCallBack, clientSocket);
Accept();
}
public void ReceiveCallBack(IAsyncResult result)
{
Socket clientSocket = result.AsyncState as Socket;
int BufferSize = clientSocket.EndReceive(result);
byte[] packet= new byte[BufferSize];
Array.Copy(_buffer,packet,packet.Length);
_buffer = new byte[1024];
clientSocket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, ReceiveCallBack, clientSocket);
}
}
}