![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3
![]() |
more on sockets
Alright two questions:
1) Right now i run my client application, i enter the hostname and i use the getbyhostname() function to get its IP. then connect that host on whatever port. I want to prompt the user for the ip to connect to instead of hostname. so the user enters a string xxx.xxx.xxx.xxx and i want i need to set the struct sockaddr_in 's IP address to the IP address entered then connect to it. so how do i do that? how do i connect to a server just by knowing the IP address of that server and the port i want to connect to. 2) i use the sendto() function to send a certain char* from client to server. my server recieves it using: int clen = sizeof (sockaddr_in); int size = recvfrom(sd,temp,strlen(temp),0,(struct sockaddr *) &client,&clen); //get recieved input and put in temp thanks for the help guys. sorry i blabbed alot, just trying to clarify. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3
![]() |
ok i found an answer to my first question... use this line of code:
sendhost.sin_addr.S_un.S_addr = inet_addr(IP); and sendhost is of type sockaddr_in |
|
|
|
|
|
#3 |
|
Hobbyist
Join Date: Sep 2005
Posts: 266
Rep Power: 4
![]() |
strlen returns the number of bytes (char's) already in the arrary. Perhaps you want sizeof(temp); instead.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|