Connection time out in socket programming

Hi everyone, I wrote c# server socket program in window and c client socket program in Linux. Between them I connected with crossover cable. And when I run my server and client program, I got connection time out error at my client side.
my client c program is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <sys/socket.h>  //for socket(), connect(), sendto() and recvform()
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>  // for printf() and fprintf()
#include <string.h>  //for memset()
#include <stdlib.h>   //for atoi() and exit()
#include <unistd.h>  //for close()
#include <errno.h>
#include <arpa/inet.h>  //for sockaddr_in and inet_addr()
 

#define SERVERPORT 11000 

int main(void)
{
	int sockfd  = 0, n =0;
	struct sockaddr_in serv_addr;
	
	//char recvBuff[1024];
	
	
	if((sockfd=socket(PF_INET, SOCK_STREAM,IPPROTO_TCP))< 0)
	{
		printf("Cannot create socket\n");
		return 1;
	}
	
	printf("Already create socket!!!\n");
	memset(&serv_addr, '0', sizeof(serv_addr));
//	memset(recvBuff, '0', sizeof(recvBuff));
	serv_addr.sin_family = AF_INET;  //AF_INET is IP address family, Internet = IP addr 	
	serv_addr.sin_addr.s_addr = inet_addr("192.168.1.1");  //sin_addr = ip addr	
	serv_addr.sin_port = htons(49252);  //sin_port = tcp/ip port no		
	//serv_addr.sin_port =ntohs(49252); 
	//serv_addr.sin_port = 0;
	//memset(&serv_addr, '0', sizeof(serv_addr));
	
	
		if(connect(sockfd,(struct sockaddr*)&serv_addr,sizeof(serv_addr)) < 0) 
		{
			perror("Cannot connect\n");	
			close(sockfd);		
			exit (1);
		}
		else
		{ 
			printf("Connected\n");
			return 0;
		}
		
				
	return 0;
}


my server c# code is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Drawing.Imaging;


namespace server_window
{
    public partial class Form1 : Form
    {
        static TcpListener tcpListener = new TcpListener(IPAddress.Parse("192.168.1.2"), 49252);
        TcpClient socketForClient;
        EndPoint ep;
        string IP;
             public Form1()
        {
            InitializeComponent();
            BW_Connection.RunWorkerAsync();
        }

        private void BW_Connection_DoWork(object sender, DoWorkEventArgs e)
        {
           tcpListener.Start();
            socketForClient = tcpListener.AcceptTcpClient();
            ep = socketForClient.Client.RemoteEndPoint;
              IP = ep.ToString();
            this.Invoke(new MethodInvoker(delegate { TB_text.Text = IP; }));
            
                 }

     
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

            //clientSocket.Close();
            socketForClient.Close();
        }



       
    }
}


why is it so? pls kindly guide me. Thanks millions
I would expect the server to listen on address INADDR_ANY. And you ports don't match.
Yes. When I changed IPAddress.Any in server side, the socket can open. But I don't know how to send text from client to server.
Topic archived. No new replies allowed.