c7bb
![]() |
|
|
|
|
|||||||
| Userland Programming & Scripting C, Shell, Perl, Sed & Awk |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
telnet session will connect, but I cannot communicate during session. I don't see the customized welcome message for each new accepted connection that is in the program. I type in the telnet window, but the program doesn't receive the message.
If I do netstat -a I see the Recv-Q with bytes of pending data, but Send-Q is empty. I executed different programming projects, from different websites, but same results. So I assume that my firewall settings are to blame. [ see http://forums.freebsd.org/showthread.php?t=31340 -- Mod. ] Please, any suggestions? Code:
int status, socketFileDesc, newFileDesc, bytes_sent, len;
struct addrinfo hints;
struct addrinfo *result;
struct sockaddr_storage their_addr;
socklen_t addr_size;
char buff[4096];
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET; //IPV4
hints.ai_socktype = SOCK_STREAM; //TCP stream sockets
hints.ai_flags = AI_PASSIVE; //fills in local IP address automatically
getaddrinfo(NULL, "3490", &hints, &result );
socketFileDesc = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
bind(socketFileDesc,result->ai_addr, result->ai_addrlen);
listen(socketFileDesc, BACKLOG);
strcpy(buff, "Hello Process \n");
while(1){
addr_size = sizeof(their_addr);
newFileDesc = accept(socketFileDesc, (struct sockaddr *) &their_addr, &addr_size);
len = strlen(buff);
send(newFileDesc, buff,len , 0);
}
Last edited by DutchDaemon; April 14th, 2012 at 04:43. |
|
#2
|
|||
|
|||
|
Code:
hints.ai_family = AF_INET; //IPV4 hints.ai_socktype = SOCK_STREAM; //TCP stream sockets -hints.ai_flags = AI_PASSIVE; //fills in local IP address automatically +hints.ai_flags = AI_NUMERICSERV | AI_PASSIVE; getaddrinfo(NULL, "3490", &hints, &result );
__________________
Don't ask what Beastie can do for you; ask what you can do for Beastie! |
|
#3
|
|||
|
|||
|
Thanks for the suggestion PseudoCylon but same result.
I decided to use the "older" way of setting up for socket programming. I was able to get it to work temporarily, but I'm not sure how since I deleted and redone all the steps in my first thread that is linked in the first post. But after a while of working (displaying hello to all new connections), it would just connect and not display anything. I would have to restart the entire computer to get it to work temporarily again, then it would stop again. Here is the code I got to temporarily work from a website. Code:
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#define BACKLOG 10 //pending connections queued
int main()
{
int servsock, backlog, err,cliLen, clisock, numBytes;
struct sockaddr_in servaddr, cliaddr;
servsock = socket( AF_INET, SOCK_STREAM, 0);
memset( &servaddr, 0, sizeof(servaddr) );
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(3490);
servaddr.sin_addr.s_addr = inet_addr("192.168.0.111");
char buff[4096];
err = bind( servsock, (struct sockaddr *)&servaddr,sizeof(servaddr));
listen(servsock,BACKLOG);
strcpy(buff, "Hello Process");
while(1){
cliLen = sizeof(cliaddr);
clisock = accept( servsock, (struct sockaddr *)&cliaddr, &cliLen );
send(clisock,buff, strlen(buff), MSG_DONTWAIT);
//numBytes = recv(clisock, buff,sizeof(buff),MSG_DONTWAIT);
// recv(clisock, buff,sizeof(buff), MSG_PEEK);
//printf(buff);
close(clisock);
}
}
Are there any terminal commands to free up any references to a socket that has been closed? Or close a socket that is listening, even though the program that initialized it has already been closed? Last edited by DutchDaemon; April 15th, 2012 at 02:33. |
|
#4
|
|||
|
|||
|
Just researched how to kill processes. I'm using the "old version" of socket programming that I posted above. I'll kill the suspecting processes that may still be referencing ports, even though my program closed.
So the following steps I will use when there is too much reference to the same port and/or too many anonymous references to ports; which may have occurred as I continually ran/stop the program. Code:
netstat -a Code:
lsof -i -n Code:
kill -9 PID These steps are a temporary solution for, until I find a permanent solution for this issue. It keeps me from continually having to restart my program. Thanks for all your help guys. EDIT: make sure you have root credentials while in the terminal that you are running the above code, this ensures you get more information when you run the lsof command. Last edited by DutchDaemon; April 15th, 2012 at 02:35. Reason: Mind your writing style: http://forums.freebsd.org/showthread.php?t=18043 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PF firewall setting for network programming | Vitamin | Firewalls | 6 | April 14th, 2012 03:16 |
| unstable network connection | frankcheong | Networking | 8 | January 4th, 2011 03:25 |
| Odd network connection behavior. | Avanesov | Networking | 5 | October 4th, 2010 16:25 |
| Getting a network connection in VMWare | rl2hb | Installing & Upgrading | 4 | February 27th, 2009 15:29 |
| Check connection with timeout, script telnet web server in script | bsddaemon | Web & Network Services | 5 | December 7th, 2008 14:03 |