|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
C e socket
sono abbastanza bravo a programmare in C ma non ho mai utilizzato i socket...come IDE uso turbo C della borland...dove posso trovare una guida ai socket e le librerie che mi mancano??
grazie |
|
|
|
|
|
#2 |
|
Bannato
Iscritto dal: Mar 2002
Città: Pescara - 未婚・恋人なし Moto: Honda CBR 1000 RR Casco: XR1000 Diabolic 3
Messaggi: 27578
|
Dipende da che socket devi usare. Essi dipendono dal sistema operativo. Per i socket Unix trovi quanta documentazione vuoi. Per il Borland C dovresti chiedere a Borland ...
|
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
Quote:
|
|
|
|
|
|
|
#4 |
|
Bannato
Iscritto dal: Mar 2002
Città: Pescara - 未婚・恋人なし Moto: Honda CBR 1000 RR Casco: XR1000 Diabolic 3
Messaggi: 27578
|
Guarda io sotto Windows non sono molto preparato ma posso dirti che un insieme abbastanza grosso delle socket Unix funziona anche sotto Windows. Esistono anche le Windows Socket ma pare ne parlino male. Male che va, ti scarichi cygwin
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Windows usa dei wrapper per implementare i socket BSD standard. L'unico fastidio è la necessità di chiamare una funzione in più di inizializzazione tipica di win32. Le funzioni BSD-like sono mappate sulle API Winsock, e sono abbastanza aderenti allo standard.
Se non hai necessità che il tuo programma possa essere portato su altri sistemi operativi, ti consiglio di studiarti la libreria Winsock, che è l'ambiente naturale per win32. Altrimenti, usa le funzioni BSD standard. Alcuni ambienti di sviluppo (ad es. Borland Builder ecc.) forniscono funzioni (classi) per maneggiare i socket in maniera molto agevole. Usandele però perdi non solo la compatibilità con altri sistemi operativi, ma anche con altri compilatori. A te la scelta
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#6 | |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
Quote:
|
|
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Per dos non è semplice (il dos non ha di per se uno stack ip). Ti consiglio almeno win32 (anche console su win32, non è necessario che programmi in interfaccia grafica).
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#8 | |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
Quote:
cmq non è che mi potresti indirizzare a qualche doc?? grazie |
|
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Se installi un compilatore "moderno" (builder, vc ecc.) ti viene anche installato il file .hlp di winsock.
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#10 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Con Turbo C è quasi impossibile... Turbo C genera eseguibili a 16 bit esclusivamente epr DOS... Quidni non puoi utilizzare lo stack TCP/IP di Windows...
Per i socket su Windows sono praticamente uguale a quelli Linux... Non si possono usare read e write, ma solo send e recv... |
|
|
|
|
|
#11 |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
mmm quindi che compilatore mi conviene scaricare??
devc++ va bene?? |
|
|
|
|
|
#12 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Come compilatore sicuramente MinGW...come IDE MinGW Developer Studio o Dev-C++...vedi tu....
|
|
|
|
|
|
#13 | |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
Quote:
su google non trovo nulla di ben chiaro.... grazie |
|
|
|
|
|
|
#14 |
|
Bannato
Iscritto dal: Mar 2002
Città: Pescara - 未婚・恋人なし Moto: Honda CBR 1000 RR Casco: XR1000 Diabolic 3
Messaggi: 27578
|
|
|
|
|
|
|
#15 |
|
Bannato
Iscritto dal: Mar 2002
Città: Pescara - 未婚・恋人なし Moto: Honda CBR 1000 RR Casco: XR1000 Diabolic 3
Messaggi: 27578
|
Potrebbe esserti utile anche la F.A.Q.:
http://tangentsoft.net/wskfaq/ |
|
|
|
|
|
#16 |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
ho provato alcuni esempi...ma non ne va nemmeno uno...
non so se è colpa di dev-c++... cmq mi da sempre questo errore [Linker error] undefined reference to `WSAStartup@8' e anche molti altri.... non è che qualcuno ha un esempio funzioanante?? |
|
|
|
|
|
#17 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Devi linkare il file libws2_32.a al progetto !!!
|
|
|
|
|
|
#18 |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
ok ora funziona
però per esempio ho provato questo programma Codice:
#include <winsock.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MESSAGE "Hello, Server!\n"
int main(int argc, int **argv)
{
WSADATA wsda; // Structure to store info
// returned from WSAStartup
struct hostent *host; // Used to store information
// retreived about the server
char szMessage[80];
int iMessageLen;
int ret;
char szInBuffer[128];
int iBufferLen;
char szAddress[64];
int iPort;
SOCKET s; // Our TCP socket handle
SOCKADDR_IN addr; // The host's address
// Check arguments
if(argc != 3 ||
(argc==2 && strcmp((char *) &argv[1][0], "/?")==0))
{
printf("wsclient server port\n");
printf(" server: the server to connect to\n");
printf(" port: the port on the remote server \n");
exit(1);
}
// Copy the IP address
strcpy(szAddress, (char *) &argv[1][0]);
// Get the remote port
iPort = atoi((char *) &argv[2][0]);
if(iPort<0 || iPort>65563)
{
printf("Invalid port number! (%s)\n", argv[2]);
exit(1);
}
// Copy the pre-defined message into a buffer
strcpy(szMessage, MESSAGE);
iMessageLen = strlen(szMessage);
// Load version 1.1 of Winsock
WSAStartup(MAKEWORD(1,1), &wsda);
// Create a TCP socket
printf("Creating socket...");
s = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
// Error?
if(s == SOCKET_ERROR)
{
printf("Error\nCall to socket(AF_INET, SOCK_STREAM, IPPROTO_IP); failed with:\n%d\n", WSAGetLastError());
exit(1);
}
printf("OK\n");
// Fill in the host information
addr.sin_family = AF_INET;
addr.sin_port = htons(iPort);
addr.sin_addr.s_addr = inet_addr(szAddress);
if(addr.sin_addr.s_addr == INADDR_NONE) // The address wasn't in numeric
// form, resolve it
{
host = NULL;
printf("Resolving host...");
host = gethostbyname(szAddress); // Get the IP address of the server
// and store it in host
if(host == NULL)
{
printf("Error\nUnknown host: %s\n", szAddress);
exit(1);
}
memcpy(&addr.sin_addr, host->h_addr_list[0],
host->h_length);
printf("OK\n");
}
// Connect to the server
printf("Connecting to %s:%d...",szAddress, iPort);
ret = connect(s, (struct sockaddr *) &addr, sizeof(addr));
if(ret == SOCKET_ERROR)
{
printf("Error\nCall to connect(s, (SOCKADDR) addr, sizeof(addr)); failed with:\n%d\n", WSAGetLastError());
exit(1);
}
printf("OK\n");
// Ready to send data
printf("Sending data...");
ret = send(s, szMessage, iMessageLen, 0);
if(ret == SOCKET_ERROR)
{
printf("Error\nCall to send(s, szMessage, iMessageLen, 0) failed with:\n%d\n", WSAGetLastError());
exit(1);
}
printf("OK\n");
printf("\"%s\" sent to %s\n", szMessage, szAddress);
// Receive data
printf("Waiting for a response...");
ret = recv(s, szInBuffer, sizeof(szInBuffer), 0);
if(ret == SOCKET_ERROR)
{
printf("Error\nCall to recv(s, szInBuffer, sizeof(szInBuffer), 0); failed with:\n%d\n", WSAGetLastError());
exit(1);
}
printf("Response recieved\n");
iBufferLen = ret; // recv() returns the number of bytes read
szInBuffer[iBufferLen] = '\0'; // convert to cstring
printf("Response recieved from %s:\n\"%s\"\n", szAddress, szInBuffer);
closesocket(s);
WSACleanup();
return 0;
}
|
|
|
|
|
|
#19 |
|
Senior Member
Iscritto dal: Jun 2002
Città: Milano
Messaggi: 959
|
no scusa!!funziona!!grazie mille!
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 05:46.



















