How to send and receive data use the same port?
-
what type of xfer and client or server??
-
what type of xfer and client or server??
and are you talking about send files or just communcating...?
-
//basic send and recieve is... #include #include #pragma comment(lib,"ws2_32") WSAData wsaData; WORD wVersionRequested; wVersionRequested=MAKEWORD(2, 2); WSAStartup( wVersionRequested, &wsaData ); std::string rawcmd; SOCKET communcationsock; SOCKET ListenSocket; SOCKADDR_IN service; ListenSocket = socket(AF_INET, SOCK_STREAM, 0); service.sin_family = AF_INET; service.sin_addr.s_addr = INADDR_ANY; service.sin_port = htons(21); if (bind( ListenSocket, (SOCKADDR*) &service, sizeof(service)) == SOCKET_ERROR) { printf("bind() failed.\n"); } listen( ListenSocket, 1 ); communcationsock=SOCKET_ERROR; while(communcationsock == SOCKET_ERROR) { communcationsock = accept( ListenSocket, NULL, NULL); } bytesRecv = recv( communcationsock, CMD, 128, 0 ); rawcmd.assign(CMD, bytesRecv); if(rawcmd=="..."){ char onconn[128]="Can You Hear Me\r\n"; send( communcationsock, onconn, strlen(onconn), 0 ); } //Basicallly you have to open up a socket for communication.. then you can open up //another sock separately and send files using the same principal. -- modified at 0:02 Saturday 1st July, 2006