![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
Hehe, well, I said I was done for the day, but it's now 12:10 AM and it's a new day. So, I have a question, would someone mind proof-reading this segment of code? It's a function to listen for WinSock. I know that it is probably way off and not functional, but I'm trying, especially with the paremeters in the function, I don't think I placed them 'inside' the function correctly...
int WinSockListen(int Ip, int Port, int backlog){
listenS = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (listenS == INVALID_SOCKET)
{
WinSockCloseSocket(listenS);
WinSockClose();
return EXIT_SUCCESS;
}
SOCKADDR_IN info;
info.sin_family = AF_INET;
info.sin_addr.s_addr = Ip;
info.sin_port = htons(Port);
ret = bind(listenS,(LPSOCKADDR)&info,sizeof(struct sockaddr));
if (ret == SOCKET_ERROR)
{
WinSockCloseSocket(listenS);
WinSockClose();
return EXIT_SUCCESS;
}
ret = listen(listenS, backlog);
if (ret == SOCKET_ERROR)
{
WinSockCloseSocket(listenS);
WinSockClose();
return EXIT_SUCCESS;
}
}Quote:
Ok, I just tested the "WinSockListen" function roughly, and heres what I get when trying to compile... I know it's gotta be something simple because its an invalid conversion! :eek: Am I supposed to change the paremeters in WinSockListen? Well, here is the attmept I have made to use the WinSockListen function in my code: case WM_COMMAND:
if((HWND)lParam == hconnectIP)
{
char IpMem[40];
char sPort[10];
GetWindowText(hPortData, sPort, sizeof(sPort));
char sIp[30];
GetWindowText(hIPData, sIp, sizeof(sIp));
strcat(IpMem, sIp);
strcat(IpMem, ":");
strcat(IpMem, sPort);
MessageBox(NULL, IpMem, "Ip and Port", MB_OK);
WinSockListen(sIp, sPort, 5);
MessageBox(NULL, "worked?", "DEBUG", MB_OK);
}
break;Quote:
)Again, thanks in advance... PS, You don't have to write any code for me :p I'd rather learn, I just need to know where I'm going wrong so I can do a little research and see how to fix it :o |
||
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
Well, obviously it's because sIp and sPort are declared as "char"'s when the paremeters for WinSockListen() are "int"'s. So, any wa around this?
|
|
|
|
|
|
#3 |
|
Programmer
|
Well, first of all you need to make the function consistent with the parameters you pass. Anyway, this thread should help:
http://www.programmingforums.org/for...ead.php?t=3602 It discusses how to convert a string to an int, so it may prove useful. kirkl_uk |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
Gotchya, totally forgot about atoi... :o Thanks!!
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|