|
Hello,
can you please share the project file.
Thanks
|
|
|
|
|
what is AfxBeginThread function header file??
|
|
|
|
|
Hello
Can you send me the zip file of the project?
I would appreciate it if you do so.
Thanks
dongseopshin@hotmail.com
|
|
|
|
|
Hi Nishant Sivakumar,
Can you send me the project file to my email address at beennan@gmail.com?
Thanks.
Regards,
beennan.
|
|
|
|
|
Hello,
Would you be so king to send me project code column.column@gmail.com
Regards,
Victor
|
|
|
|
|
i write one code for lan chatt using tcp protocol in c & client also program run on single pc perfectly but running on different computer get error i.e. binding error port buzy so please send me why this error occur
operating system: ubuntu
protacol:tcp
Two are connected to each other
server code
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
int sd,i,len,bi,nsd,port,uid;
char buffer[30];
struct sockaddr_in ser,cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\nSocket problem");
return 0;
}
printf("\nSocket created\n");
bzero((char*)&cli,sizeof(ser));
printf("ENTER PORT NO:\n");
scanf("%d",&port);
printf("\nPort Address is %d\n:",port);
ser.sin_family=AF_INET;
ser.sin_port=htons(port);
ser.sin_addr.s_addr=htonl(INADDR_ANY);
bi=bind(sd,(struct sockaddr *)&ser,sizeof(ser));
if(bi==-1)
{
printf("\nBind error, Port busy, Plz change port in client and server");
return 0;
}
i=sizeof(cli);
listen(sd,5);
nsd = accept(sd,((struct sockaddr *)&cli),&i);
if(nsd==-1)
{
printf("\nCheck the description parameter\n");
return 0;
}
printf("\nConnection accepted!");
if(fork())
{
printf("Enter user id(uid)\n");
scanf("%d",&uid);
printf("\nEnter the data to be send type exit for stop:\n");
scanf("%s",buffer);
while(strcmp(buffer,"exit")!=0)
{
// insert(uid,buffer);
send(nsd,buffer,30,0);
scanf("%s",buffer);
}
send(nsd,"exit",5,0);
}
else
i = recv(nsd,buffer,30,0);
while(strcmp(buffer,"exit")!=0)
{
printf("\nClient: %s\n",buffer);
i=recv(nsd,buffer,30,0);
}
printf("\nBye");
send(nsd,"Offline",10,0);
close(sd);
close(nsd);
return 0;
}
client code
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
int sd,con,port,i,Res,uid;
char buffer[100];
struct sockaddr_in cli;
if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
{
printf("\nSocket problem");
return 0;
}
bzero((char*)&cli,sizeof(cli));
cli.sin_family = AF_INET;
printf("ENTER PORT NO:\n");
scanf("%d",&port);
cli.sin_port=htons(port);
cli.sin_addr.s_addr=htonl(INADDR_ANY);
con=connect(sd,(struct sockaddr*)&cli,sizeof(cli));
if(con==-1)
{
printf("\nConnection error");
return 0;
}
if(fork())
{
printf("Enter user id(uid)\n");
scanf("%d",&uid);
printf("\nEnter the data to be send type exit for stop:\n");
scanf("%s",buffer);
while(strcmp(buffer,"exit")!=0)
{
// insert(uid,buffer);
send(sd,buffer,30,0);
scanf("%s",buffer);
}
send(sd,"exit",5,0);
}
else
{
i=recv(sd,buffer,30,0);
while(strcmp(buffer,"exit")!=0)
{
printf("\nServer: %s\n",buffer);
i=recv(sd,buffer,30,0);
}
send(sd,"exit",5,0);
}
close(sd);
return 0;
}
|
|
|
|
|
Please send me code zip file to chetan.k7845@gmail.com
|
|
|
|
|
Please send me the zipped project file. I have problems compiling your code correctly.
Thank you and best wishes for you and your family.
Victor
vnla@hotmail.com
|
|
|
|
|
This is really nice piece of work. I most enjoyed the simple explanations and direct example.
|
|
|
|
|
Hi Nishant Sivakumar,
Can you send me the project file to my email address at byronli66@qq.com?
Thanks.
best Regards
|
|
|
|
|
hi. nish
i have to write a program in which the client send the http request to server for receive the file .server provide the client a http url and on hitting the url the client data send to server.
i am using window environment + visual st. for writing program in c lang.
i have make client-server program using winsock api. which work fine for sending data but in this case the send has to listen for client and then client execute.
But i want that client send req. to server url and file transfer.how it can be if we send file from client side how server received it from it end. help
|
|
|
|
|
Would it be possible for you to send me the zipped project file? I have problem compiling your code correctly and maybe i could learn more by having the actual project file.
Thanks you and wishes you and your family the best.
fabmkk@gmail.com
|
|
|
|
|
Hi Nishant Sivakumar,
Can you send me the project file to my email address at ikurtoglu@yahoo.com?
Thanks.
Regards,
Ismail
|
|
|
|
|
sorry can u send to sheran_silva@hotmail.com
that would be much appreciated
sheran
|
|
|
|
|
hey can u send me the file
thx
|
|
|
|
|
Hi Nishant Sivakumar,
Can you send me the project file to my email address at cafukarfoo@yahoo.com?
Thanks.
Regards,
Chong kar foo
|
|
|
|
|
Dear Nis!
Excellent Article!
Thanks!
|
|
|
|
|
dear Mr.Nishant,
i need the source code for this project.i am not able to compile it.can you please send me the zip file to my email id, aarthi.krishnan@yahoo.com
thank you
aarthi krishnan
|
|
|
|
|
thanks for this code and can you send zip file of it.
|
|
|
|
|
hello,i was wondering if you could help me in a beginners and i would like to learn socket programming was wondering if you could send me the zip file for this code thank you my email is
"hwzlake@163.com"
thanks
|
|
|
|
|
Compiling...
server.cpp
h:\vc++ exercies in vs 6.0\server\server.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/server.pch': No such file or directory
Error executing cl.exe.
server.obj - 1 error(s), 0 warning(s)
How to solve....
i have choose radio button as MFC suport, Add this 2 code to server.cpp file.
also add ws2_32.lib to setting-->link
server.cpp
---------------------------------------------------------------------------------------
// server.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "server.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
#include<windows.h>
#include <afxwin.h>
using namespace std;
iint _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
cout << "Press ESCAPE to terminate program\r\n";
AfxBeginThread(ServerThread,0);
while(_getch()!=27);
return nRetCode;
}
UINT ServerThread(LPVOID pParam)
{
cout << "Starting up TCP server\r\n";
//A SOCKET is simply a typedef for an unsigned int.
//In Unix, socket handles were just about same as file
//handles which were again unsigned ints.
//Since this cannot be entirely true under Windows
//a new data type called SOCKET was defined.
SOCKET server;
//WSADATA is a struct that is filled up by the call
//to WSAStartup
WSADATA wsaData;
//The sockaddr_in specifies the address of the socket
//for TCP/IP sockets. Other protocols use similar structures.
sockaddr_in local;
//WSAStartup initializes the program for calling WinSock.
//The first parameter specifies the highest version of the
//WinSock specification, the program is allowed to use.
int wsaret=WSAStartup(0x101,&wsaData);
//WSAStartup returns zero on success.
//If it fails we exit.
if(wsaret!=0)
{
return 0;
}
//Now we populate the sockaddr_in structure
local.sin_family=AF_INET; //Address family
local.sin_addr.s_addr=INADDR_ANY; //Wild card IP address
local.sin_port=htons((u_short)20248); //port to use
//the socket function creates our SOCKET
server=socket(AF_INET,SOCK_STREAM,0);
//If the socket() function fails we exit
if(server==INVALID_SOCKET)
{
return 0;
}
//bind links the socket we just created with the sockaddr_in
//structure. Basically it connects the socket with
//the local address and a specified port.
//If it returns non-zero quit, as this indicates error
if(bind(server,(sockaddr*)&local,sizeof(local))!=0)
{
return 0;
}
//listen instructs the socket to listen for incoming
//connections from clients. The second arg is the backlog
if(listen(server,10)!=0)
{
return 0;
}
//we will need variables to hold the client socket.
//thus we declare them here.
SOCKET client;
sockaddr_in from;
int fromlen=sizeof(from);
while(true)//we are looping endlessly
{
char temp[512];
//accept() will accept an incoming
//client connection
client=accept(server,
(struct sockaddr*)&from,&fromlen);
sprintf(temp,"Your IP is %s\r\n",inet_ntoa(from.sin_addr));
//we simply send this string to the client
send(client,temp,strlen(temp),0);
cout << "Connection from " << inet_ntoa(from.sin_addr) <<"\r\n";
//close the client socket
closesocket(client);
}
//closesocket() closes the socket and releases the socket descriptor
closesocket(server);
//originally this function probably had some use
//currently this is just for backward compatibility
//but it is safer to call it as I still believe some
//implementations use this to terminate use of WS2_32.DLL
WSACleanup();
return 0;
}
|
|
|
|
|
Hi Nishant,
I am having just one month of experience in network programming. I want to trace TCP packets using winsock. I could right the code for that as below. It worked on XP 32 bit but not on Vista Home 32 bit machine.
SOCKET sniffSocket;
if((sniffSocket= socket(AF_INET, SOCK_RAW, IPPROTO_IP))==SOCKET_ERROR)
{
return 0;
}
struct sockaddr_in src;
memset(&src, 0, sizeof(src));
src.sin_addr.S_un.S_addr = inet_addr (pAdapterInfo->IpAddressList.IpAddress.String);
src.sin_family = AF_INET;
src.sin_port = 0;
if (bind(sniffSocket,(struct sockaddr *)&src, sizeof(src)) == SOCKET_ERROR)
{
return 0;
}
int j=1;
if (WSAIoctl(sniffSocket, SIO_RCVALL, &j, sizeof(j), 0, 0, &in, 0, 0) == SOCKET_ERROR)
{
return 0;
}
char *pkt_data = (char *)malloc(65536);
int res;
do
{
res = recvfrom(sniffSocket, pkt_data, 65536, 0, 0, 0);
...
...
}
while (res > 0);
...
...
The above code is working fine on XP. I could trace TCP/IP packets (in variable pkt_data) this way. But when I run the same code on Vista, I am able to trace just UDP/IP packets. Can you tell me why is it not working on Vista?
I hope you can resolve my problem.
My second query: When we type a web-site address on a browser, we don't tell which adapter to connect to. Browser automatically opens adapter that is connected to internet. How it does that? I mean how can I detect which adapter is being used for internet connection?
Thanks in Advance
Regards
Aseem
modified on Wednesday, December 23, 2009 1:48 AM
|
|
|
|
|
|
Hi Nishant !!
Thnx for the excellent Post , however can you send the project zip file to my email id
yithape@gmail.com
|
|
|
|
|
Dear Mr.Nishant,
can you plz send me the zip file for this project? My email is lwang@u-systems.com. Thank you!
|
|
|
|
|