Skocz do zawartości

socket parę pytań :)


Parody

Recommended Posts

Elo.
Parę pytanek na temat socket’ów
1. Jak zrobić żeby wysłać do wszystkich adresów lub wcześniej
zdefiniowanej grupy ?
2. Czy można wysłać jakoś bez connect() ?
3. Czy ktoś może mi wyjaśnić funkcje sendto() albo dać link do tutoriala ?
4. Lepiej pisać programy sieciowe przy użyciu socket’ów czy może
DirectPlay ?
Z góry dzięki za pomoc :)

Link do komentarza
Udostępnij na innych stronach

Ad1. Żeby wyslac do wielu adresow lub do uzytkownikow zarejestrowana jedna nazwa sieciowa trzeba uzyc datagramow(rozglaszanie).
Ad2. Wlasnie datagramy daja ta mozliwosc ze zeby wyslac cos do klienta nie trzeba nawiazywac polaczenia. Nie trzeba uzywac connect() ale nie masz pewnosci ze dane zostana w calosci dostarczone.
A na reszte pytan odpowiem jak dostudiuje :D

Link do komentarza
Udostępnij na innych stronach

Ad3. Funkcja sendto() wysyla dane do okreslonej lokacji (gniazda). Ma postac:
int sendto (
SOCKET s,
const char FAR * buf,
int len,
int flags,
const struct sockaddr FAR * to,
int tolen
);
gdzie:
s - socket z ktorego wysylasz
buf - bufor danych ktore wysylasz
len - wielkosc wsylanych danych
flags - flagi okreslajace rodzaj wysylania (MSG_DONTROUTE, MSG_OOB)
to - adres socketa do ktorego sa wysylane dane
tolen - rozmiar adresu do ktorego wysylasz dane

zwracane wartosci (skopiowane z MSDN):
WSANOTINITIALISED A successful WSAStartup must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAEACCES The requested address is a broadcast address, but the appropriate flag was not set. Call setsockopt with the SO_BROADCAST parameter to allow the use of the broadcast address.
WSAEINVAL An unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled.
WSAEINTR A blocking Windows Sockets 1.1 call was canceled through WSACancelBlockingCall.
WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEFAULT The buf or to parameters are not part of the user address space, or the tolen parameter is too small.
WSAENETRESET The connection has been broken due to "keep-alive" activity detecting a failure while the operation was in progress.
WSAENOBUFS No buffer space is available.
WSAENOTCONN The socket is not connected (connection-oriented sockets only)
WSAENOTSOCK The descriptor is not a socket.
WSAEOPNOTSUPP MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, out-of-band data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only receive operations.
WSAESHUTDOWN The socket has been shut down; it is not possible to sendto on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH.
WSAEWOULDBLOCK The socket is marked as nonblocking and the requested operation would block.
WSAEMSGSIZE The socket is message oriented, and the message is larger than the maximum supported by the underlying transport.
WSAEHOSTUNREACH The remote host cannot be reached from this host at this time.
WSAECONNABORTED The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable.
WSAECONNRESET The virtual circuit was reset by the remote side executing a "hard" or "abortive" close. For UPD sockets, the remote host was unable to deliver a previously sent UDP datagram and responded with a "Port Unreachable" ICMP packet. The application should close the socket as it is no longer usable.
WSAEADDRNOTAVAIL The remote address is not a valid address, for example, ADDR_ANY.
WSAEAFNOSUPPORT Addresses in the specified family cannot be used with this socket.
WSAEDESTADDRREQ A destination address is required.
WSAENETUNREACH The network cannot be reached from this host at this time.
WSAETIMEDOUT The connection has been dropped, because of a network failure or because the system on the other end went down without notice.

Link do komentarza
Udostępnij na innych stronach

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gość
Odpowiedz...

×   Wkleiłeś zawartość bez formatowania.   Usuń formatowanie

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Utwórz nowe...